既可以支持整数四则运算,也可以支持分数四则运算,可定制出题数量的c语言程序

#include<stdio.h>
#include <stdlib.h>
#include<conio.h>
#include<time.h>
int main()
{
int r=0;
int a=0;
int b=0;
int p=0;
int q=0;
int g=0;
int h=0;
int m=0;
int i,t,n,k,s,c;
scanf("%d",&n);
srand((unsigned)time(NULL));
for(i=0;i<n;i++)
{
a=rand()%100;
b=rand()%100;
p=rand()%100;
q=rand()%100;
g=rand()%100;
h=rand()%100;
m=rand()%8;
if(q<p)
{
k=q;
q=p;
p=k;
}
if(h<g)
{
s=g;
g=h;
h=s;
}
if(a<b)
{
t=a;
a=b;
b=t;
}
switch(m)
{
case 0:
printf("\n%d+%d=",a,b,a+b);
r=a+b;
break;
case 1:
printf("\n%d-%d=",a,b,a-b);
r=a-b;
break;
case 2:
printf("\n%d*%d=",a,b,a*b);
r=a*b;
break;
case 3:
printf("\n%d/%d=",a,b,a/b);
r=a/b;
break;
case 4:
printf("\n%d/%d+%d/%d=",p,q,g,h,p/q+g/h);
r=p/q+g/h;
break;
case 5:
printf("\n%d/%d-%d/%d=",p,q,g,h,p/q-g/h);
r=p/q-g/h;
break;
case 6:
printf("\n%d/%d*%d/%d=",p,q,g,h,p/q*g/h);
r=p/q*g/h;
break;
case 7:
printf("\n%d/%d/%d/%d=",p,q,g,h,p/q/g/h);
r=p/q/g/h;
break;
default:
printf("something is wrong!\n");
break;
}
printf("\n");
scanf("%d",&c);
if(c==r)
printf("right\n\n");
else
{
printf("wrong\n\n");
}
return 0;
}

猜你喜欢

转载自www.cnblogs.com/09-15/p/9765845.html