标签:
组员:李登辉。袁爱。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a,b,ans,res,t,i,c=0,N;
int op;
srand((unsigned)time(NULL));
while(1)
{
printf("\n---简单四则运算练习系统---\n");
printf("1.进行加法运算\n");
printf("2.进行减法运算\n");
printf("3.进行乘法运算\n");
printf("4.进行除法运算\n");
printf("5.退出练习\n");
printf("请输入数字1-5:\n");
scanf("%d",&op);
switch(op)
{
case 1:
printf("--请进行加法运算--\n");
printf("--请输入题目个数--\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
a=rand()%9+1;
b=rand()%9+1;
res=a+b;
printf("%d+%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
{
printf("wrong answer\n");
printf("你还有一次机会\n");
printf("%d+%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
printf("wrong answer\n");
}
}
printf("***正确率为%.0f%%***\n",100.0*c/N);
break;
case 2:
printf("--请进行减法运算--\n");
printf("--请输入题目个数--\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
a=rand()%9+1;
b=rand()%9+1;
if(a<b)
{t=a;a=b;b=t;}
res=a-b;
printf("%d-%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
{
printf("wrong answer");
printf("你还有一次机会\n");
printf("%d-%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
printf("wrong answer\n");
}
}
printf("***正确率为%.0f%%***\n",100.0*c/N);
break;
case 3:
printf("--请进行乘法运算--\n");
printf("--请输入题目个数--\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
a=rand()%9+1;
b=rand()%9+1;
res=a*b;
printf("%d*%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
{
printf("wrong answer");
printf("你还有一次机会\n");
printf("%d*%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
printf("wrong answer\n");
}
}
printf("***正确率为%.0f%%***\n",100.0*c/N);
break;
case 4:
printf("--请进行除法运算--\n");
printf("--请输入题目个数--\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
a=rand()%9+1;
b=rand()%9+1;
res=a*b/b;
printf("%d/%d=",a*b,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
{
printf("wrong answer");
printf("你还有一次机会\n");
printf("%d/%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good!\n");
c++;
}
else
printf("wrong answer");
}
}
printf("***正确率为%.0f%%***\n",100.0*c/N);
break;
case 5:goto END;
}
}
END:printf("---Bye Bye---\n");
return 0;
}
总结:普通的编程都不会,这些就更完全看不懂啊,请谅解!这种作业对于我们这些成绩不好的同学来说简直难如登天!
标签:
原文地址:http://www.cnblogs.com/rjgc123/p/4451305.html