四则运算

|博客班级 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/ |
|作业要求 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11376|
|作业目标 | 写一个能自动生成小学四则运算题目的程序 |
|学号 | 3190704202 |

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;

}
}

posted on 2020-11-02 19:31  马智强  阅读(106)  评论(0编辑  收藏  举报

导航