随机产生3个整数的加减混合运算
注意windows.h头文件里的sleep
#include "stdio.h" #include#include #include int * random()//Generate random numbers 1 to 20 { static int r[3]; srand((unsigned int)time(NULL));//修改种子 for (int i = 0; i < 3; i++) { r[i]=rand()%(20) + 1;//设置范围 1-20 Sleep(500); // windows.h } return r; } int * random01()//Generate random numbers 1 or 0 { static int rr[3]; srand((unsigned int)time(NULL));//修改种子 for (int i = 0; i < 3; i++) { rr[i]=rand();//设置范围 1-20 Sleep(500); // windows.h } return rr; } int main(int argc, char const *argv[]) { int *p;// build a pointer p=random(); int *q;// build a pointer q=random01(); char a[2]={'+','-'}; printf("%d%c%d%c%d=",*(p+0),a[*(q+0)%2],*(p+1),a[*(q+1)%2],*(p+2)); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)