C语言中随机函数是怎么写的?

yudh 2002-12-23 03:42:38
C语言中随机函数是怎么写的?数字转换为字符串有怎么写的?谁有C语言的教程或帮助,能否给我一个

...全文
64 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
trancebaby 2002-12-23
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1270/1270946.xml?temp=.1090814
monster2002 2002-12-23
  • 打赏
  • 举报
回复
sorry,第三行是
if((sign=n)<0)
monster2002 2002-12-23
  • 打赏
  • 举报
回复
/* itoa: 将数字n换成字符村到s中 */
void itoa(int n, char s[]);
{
int i,sign;
if((sign=n),0)
n=-n;
i=0;
do{
s[i++]=n%10+'0';
}while((n/=10)>0;
if(sign<0)
s[i++]='-';
s[i]='\0';
reverse(s);
}
lixiaolong3456 2002-12-23
  • 打赏
  • 举报
回复
这个好象是将数字转换成字符窜的函数
yudh 2002-12-23
  • 打赏
  • 举报
回复
itoa()函数怎么用的。不好意思,我手边没有帮助
zhangyilan 2002-12-23
  • 打赏
  • 举报
回复
随机函数rand()使用之前需要设定随机种子srand()
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}

数字转换为字符串 itoa()

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧