首页 > 代码库 > 四则运算

四则运算

#include<stdio.h>#include<string.h>#include<time.h>#include<stdlib.h>int main(){      char str[]="+-*/";  srand(time(0));      int res[10];      for(int i = 0;i<=9;i++)      {            int a = rand()%100+1;            int b = rand()%100+1;            int c = rand()%4;            if(c==3)            {                while(a%b) a = rand()%100+1,b = rand()%100+1;                 }            printf("%d %c %d\n",a,str[c],b);            if(c==0) res[i] = a+b;            else if(c==1) res[i] = a-b;            else if(c==2) res[i] = a*b;            else res[i] = a/b;      }      int s[10];      printf("请输入答案用空格分开\n");      for(int i=0;i<=9;i++)      {       scanf("%d",&s[i]);      }      for(int i=0;i<=9;i++)      {          if(s[i]!=res[i])          {              printf("第%d道题错了,正确答案为%d\n",i+1,res[i]);           }      }      return 0;} 

 

四则运算