标签:name 随机数 没有 rand 病毒 范围 直接 section 需求分析
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int i;
//srand((unsigned)time(NULL)); //初始化随机数种子
for (i=0; i<10; i++) //产生10个随机数
{
cout<<rand()<<" ";
}
cout<<endl;
return 0;
}
include <stdio.h>
include <stdlib.h>
include <time.h>
include <math.h>
int main()
{
int i=0;
int n=0;
int x=0;
int type;
char flag;
int left, right;
float result;
printf("请输入要出的题目数量\n");
scanf("%d",&n);
srand(unsigned(time(NULL)));
while(x<n)
{
type = rand() % 4;
left = rand() % 100;
right = rand() % 100;
switch(type)
{
case 0:
printf("%d + %d = ?\n", left, right);
break;
case 1:
printf("%d - %d = ?\n", left, right);
break;
case 2:
printf("%d * %d = ?\n", left, right);
break;
case 3:
printf("%d / %d = ?\n", left, right);
break;
}
i++;
while(i>=n)
{
printf("一共 %d 题\n",i);
printf("继续?[Y/N]\n");
fflush(stdin);
scanf("%c",&flag);
if(flag==‘Y‘||flag==‘y‘)
{
printf("请输入要出的题目数量\n");
scanf("%d",&n);
i=0;
break;
}
printf("谢谢使用!\n");
fflush(stdin);
getchar();
return 0;
}
}
}
2017-2018-1 20179215 《构建之法》第一章总结
标签:name 随机数 没有 rand 病毒 范围 直接 section 需求分析
原文地址:http://www.cnblogs.com/yl-930/p/7966245.html