如何用C产生0 99随机数?
#include <stdlib.h>
#include<stdio.h>
#include<time.h>
#define randomize() srand((unsigned)time(NULL)) //定义一个宏
int main(void)
{
int i;
printf("Ten random numbers from 0 to 99\n\n");
randomize();
for(i=0; i<100; i++)
{
printf("%d\n", rand() % 100);
sleep(1);
}
return 0;
}
<运行>
root@farsight:/mnt/hgfs/E/yinhui/12.3/msg# gcc tttt.c -o tttt
root@farsight:/mnt/hgfs/E/yinhui/12.3/msg# ./tttt
Ten random numbers from 0 to 99
87
80
68
39
39
53
14
96
46
相关文档:
1.已知strcpy 函数的原型是:
char *strcpy(char *strDest, const char *strSrc);
其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy
答案:
char *strcpy(char *strDest, const char *strSrc)
{
if ( strDest == NULL || strSrc == NULL)
return NULL ;
if ( strDest ......
调试keil程序时有时会出现各种编译警告,一般情况下不会影响程序的运行。但出现如题WARNING:MULTIPLE CALL TO SEGMENT警告时,请留意您的程序是否会发生错误。上述警告指的是你定义的函数体在主程序中被调用,在中断中也被直接或间接的调用了。可想若主程序正运行此函数时,中断来临也运行这段程序的话会发生函数重载现象。 ......
#include <stdio.h>
#define N 19
int main()
{
int i;
for (i=0;i<=N;i++)
{
printf("%*.*s%-*.*s\n",N,i<=N/2?i:N-1,"*******************",\
N,i<=N/2?i+1:N-i+1,"*******************");
}
return 0;
}
%m.ns ......
搞软件是有搞头的
——邹祁峰
2009年12月3日
声明:所说的只针对C、C++、.NET专业的同学,对其他专业也许没有参考价值!
[推荐给大三的学弟学妹们]
【欢迎各位朋友补充】
对我个人而言,大学毕业找工作算是画上了一个许多人羡慕,但我自己仍感遗憾的句号。找工作期间 ......
It is better to have the ability of fast learning
有一天你覺得甚麼都知道了 可悲
有一天你卻發現你甚麼都不會 加油吧
有一天你發現你又甚麼都會了 繼續
有一天你發現你甚麼都不會了 成功了
......