四則運算
|博客班級 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/ |
|作業(yè)要求 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11376|
|作業(yè)目標 | 寫一個能自動生成小學四則運算題目的程序 |
|學號 | 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("請輸入要出的題目數(shù)量\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("繼續(xù)?[Y/N]\n");
fflush(stdin);
scanf("%c",&flag);
if(flag=='Y'||flag=='y')
{
printf("請輸入要出的題目數(shù)量\n");
scanf("%d",&n);
i=0;
break;
}
printf("謝謝使用!\n");
fflush(stdin);
getchar();
return 0;
}
}

浙公網(wǎng)安備 33010602011771號