随机四则运算(小数)阿西巴分数怎么做?!

来源:互联网 发布:数据库功能分类 编辑:程序博客网 时间:2024/04/27 22:25
#include<stdio.h>
#include<math.h>
#include<windows.h>
int right=0;
int wrong=0;
void add()
{
 float a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("请回答:\n\t\t %d + %d = ",a,b);
 scanf("%d",&c);
 if(a+b==c)
 {
  printf("回答正确!\n");
  right++;
 }
 else
 {
  printf("回答错误!\n");
  wrong++;
 }
}
void minu()
{
 float a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("请回答:\n\t\t %d - %d = ",a,b);
 scanf("%d",&c);
 if(a-b==c)
 {
  printf("回答正确!\n");
  right++;
 }
 else
 {
  printf("回答错误!\n");
  wrong++;
 }
}
void mul()
{
 float a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("请回答:\n\t\t %d * %d = ",a,b);
 scanf("%d",&c);
 if(a*b==c)
 {
  printf("回答正确!\n");
  right++;
 }
 else
 {
  printf("回答错误!\n");
  wrong++;
 }
}
void di()
{
 float a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("请回答:\n\t\t %d / %d = ",a,b);
 scanf("%d",&c);
 if(a/b==c)
 {
  printf("回答正确!\n");
  right++;
 }
 else
 {
  printf("回答错误!\n");
  wrong++;
 }
}
void main()
{
 int choise;
 int con=0;
 printf("\n\t\t\t欢迎进入小学简易四则运算\n\n");
 printf("请选择:\n");
 printf("\t\t\t  开始运算(请输入1)\n");
 printf("\t\t\t  退出运算(请输入2)\n");
 scanf("%d",&con);
 while(1)
 {
  
  if(con==1)
  switch(choise=rand()%4)
  {
  case 0:
   add();
   break;
  case 1:
   minu();
   break;
  case 2:
   mul();
   break;
  case 3:
   di();
   break;
  default:
   return -1;
  }
  else
 if(con==2)
 break;
 else
  printf("抱歉!,你输入的指令有误!请重新输入!\n");
  printf("\n\t\t\t继续运算?(请输入1)\n");
  printf("\n\t\t\t退出运算?(请输入2)\n");
  scanf("%d",&con);
  if(con==1)
   con=1;
  else if(con==2)
   break;
  else
   printf("抱歉!,你输入的指令有误!请重新输入!\n");
 }
 printf("您总共完成了 %d 道题\n正确 %d 道\n错误 %d 道\n",right+wrong,right,wrong);
}
0 0
原创粉丝点击