#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main(void)
{
float a;
float b;//生成的随机数
float sum[99]={0};//运算过后的结果
int x,y;//随机数生成范围
char k;//运算符号
int mun;//题数
int key;//判断是否工作
printf("input the first number\n");
scanf("%d",&x);
printf("Input the second number\n");
scanf("%d",&y);
printf("Input operator\n");
getchar();/*吃掉回车*/
scanf("%c",&k);
printf("Input the number of generated questions\n");
scanf("%d",&mun);
srand(time(0));
while(1)
{
switch(k)
{
//加法
case'+':
for (int i=1;i<=mun;i++)
{
a=rand()%x;
b=rand()%y;
sum[i]=a+b;
printf("第%d题:%5f + %5f = \n",i,a,b);
printf(" -----------------");
for (int i=0;i<4;i++)
printf("\n");
}
printf("The answer to this exercise is:");
for (int i=1;i<=mun;i++)
{
printf("Question%d:%f ",i,sum[i]);
}
printf("\n");
printf("----------------------------------------------------------------------------------------\n");
printf("\n");
break;
//乘法
case'*':
for (int i=1;i<=mun;i++)
{
a=rand()%x;
b=rand()%y;
sum[i]=a*b;
printf("第%d题:%5f × %5f = \n",i,a,b);
printf(" ----------------");
for (int i=0;i<4;i++)
printf("\n");
}
printf("The answer to this exercise is:");
for (int i=1;i<=mun;i++)
{
printf("Question%d:%f ",i,sum[i]);
}
printf("\n");
printf("----------------------------------------------------------------------------------------\n");
printf("\n");
break;
//除法
case'/':
for (int i=1;i<=mun;i++)
{
a=rand()%x;
b=rand()%y;
sum[i]=a/b;
printf("第%d题:%5f ÷ %5f = \n",i,a,b);
printf(" --------------------");
for (int i=0;i<4;i++)
printf("\n");
}
printf("The answer to this exercise is:");
for (int i=1;i<=mun;i++)
{
printf("Question%d:%f ",i,sum[i]);
}
printf("\n");
printf("----------------------------------------------------------------------------------------\n");
printf("\n");
break;
//减法
case'-':
for (int i=1;i<=mun;i++)
{
a=rand()%x;
b=rand()%y;
sum[i]=a-b;
printf("第%d题:%5f - %5f = \n",i,a,b);
printf(" --------------------");
for (int i=0;i<4;i++)
printf("\n");
}
printf("The answer to this exercise is:");
for (int i=1;i<=mun;i++)
{
printf("Question%d:%f ",i,sum[i]);
}
printf("\n");
printf("----------------------------------------------------------------------------------------\n");
printf("\n");
break;
}
printf("---Enter the number 1 generator to continue generating new exercise questions.\n ");
printf("---If you want to exit or edit the question information again, please enter 0\n");
scanf("%d",&key);
if(key==0)
{
break;
}
}
return 0;
}