软件工程第三次作业

组员:李登辉。袁爱。

#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(" ---简单四则运算练习系统--- ");
printf("1.进行加法运算 ");
printf("2.进行减法运算 ");
printf("3.进行乘法运算 ");
printf("4.进行除法运算 ");
printf("5.退出练习 ");
printf("请输入数字1-5: ");
scanf("%d",&op);
switch(op)
{
case 1:
printf("--请进行加法运算-- ");
printf("--请输入题目个数-- ");
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! ");
c++;
}
else
{
printf("wrong answer ");
printf("你还有一次机会 ");
printf("%d+%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good! ");
c++;
}
else
printf("wrong answer ");
}
}
printf("***正确率为%.0f%%*** ",100.0*c/N);
break;
case 2:
printf("--请进行减法运算-- ");
printf("--请输入题目个数-- ");
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! ");
c++;
}
else
{
printf("wrong answer");
printf("你还有一次机会 ");
printf("%d-%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good! ");
c++;
}
else
printf("wrong answer ");
}
}
printf("***正确率为%.0f%%*** ",100.0*c/N);
break;
case 3:
printf("--请进行乘法运算-- ");
printf("--请输入题目个数-- ");
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! ");
c++;
}
else
{
printf("wrong answer");
printf("你还有一次机会 ");
printf("%d*%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good! ");
c++;
}
else
printf("wrong answer ");
}
}
printf("***正确率为%.0f%%*** ",100.0*c/N);
break;
case 4:
printf("--请进行除法运算-- ");
printf("--请输入题目个数-- ");
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! ");
c++;
}
else
{
printf("wrong answer");
printf("你还有一次机会 ");
printf("%d/%d=",a,b);
scanf("%d",&ans);
if(ans==res)
{
printf("very good! ");
c++;
}
else
printf("wrong answer");
}
}
printf("***正确率为%.0f%%*** ",100.0*c/N);
break;
case 5:goto END;
}
}
END:printf("---Bye Bye--- ");
return 0;
}

总结:普通的编程都不会,这些就更完全看不懂啊,请谅解!这种作业对于我们这些成绩不好的同学来说简直难如登天!

原文地址:https://www.cnblogs.com/rjgc123/p/4451305.html