随机生成四则运算代码
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#include<windows.h>
#define N 50
void main()
{
int a,b,m,i,n;
double c,d;
srand(time(NULL));
do{
printf("\n请输入数字类型(1.整数 2.小数) -1为退出程序: ");
scanf("%d",&n);
switch(n)
{
case 1:
{
for(i=0;i<N;i++)
{
a=rand()%100+1;
b=rand()%100+1;
m=rand()%4+1;
printf("%d",a);
switch(m)
{
case 1:printf("+");break;
case 2:printf("-");break;
case 3:printf("*");break;
case 4:printf("/");break;
}
printf("%d=\t\t",b);
}
break;
}
break;
case 2:
{
for(i=0;i<N;i++)
{
c=rand()*0.001+1;
d=rand()*0.001+1;
m=rand()%4+1;
printf("%0.2f",c);
switch(m)
{
case 1:printf("+");break;
case 2:printf("-");break;
case 3:printf("*");break;
case 4:printf("/");break;
}
printf("%0.2f=\t",d);
}
break;
}
break;
}
}
while(n!=-1);
}