码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算

时间:2016-09-05 21:08:27      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

#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;
} 

 

四则运算

标签:

原文地址:http://www.cnblogs.com/liqiao085/p/5843501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!