vc c++ 关于随机产生两位数的+-*/算法源程序
#include<stdio.h>#include<stdlib.h>
int sum(int x,int y)
{
int l,k,h,m;
l=x+y;
k=x*y;
h=x-y;
m=x/y;
return l;
return k;
return h;
return m;
}
main()
{
int j,a,b,k,p,i,u,g;
for(j=0;j<40;j++)
{
a=rand()%100;
b=rand()%100;
}
for(g=0;g<10;g++)
{
printf("%d+%d=",a,b);
scanf("%d",&k);
if(k==sum(a,b))
printf("正确\n");
else
printf("错误\n");
printf("%d*%d=",a,b);
scanf("%d",&p);
if(p==sum(a,b))
printf("正确\n");
else
printf("错误\n");
printf("%d/%d=\n",a,b);
scanf("%d",&i);
if(i==sum(a,b))
printf("正确\n");
else
printf("错误\n");
printf("%d-%d=",a,b);
scanf("%d",&u);
if(u==sum(a,b))
printf("正确\n");
else
printf("错误\n");
}
}