编写一个能对0–10之间的整数进行四则运算的“软件”
程序能接收用户输入的整数答案,并判断对错
程序结束时,统计出答对、答错的题目数量。
0——10的整数是随机生成的
用户可以用键盘输入来选择四则运算中的一种,例如输入1代表加法运算
用户用键盘输入一个字符来结束程序的运行并显示统计结果,例如输入K 程序结束并显示统计结果
程序能接收用户输入的整数答案,并判断对错
程序结束时,统计出答对、答错的题目数量。
0——10的整数是随机生成的
用户可以用键盘输入来选择四则运算中的一种,例如输入1代表加法运算
用户用键盘输入一个字符来结束程序的运行并显示统计结果,例如输入K 程序结束并显示统计结果
(有那位愿意帮忙一下吗?编写一个完整的程序,本人是刚开始学的Csharp [C#]爱好者。谢谢!)

解决方案:40分
#include<stdio.h>
#include<time.h>
int a,b,c,ch,JieGuo,Lv;
void ShuoMing()
{
printf(“–程序说明–/\n”);
printf(“|输入 +号表示选择加法 |\n”);
printf(“|输入 -号表示选择加法 |\n”);
printf(“|输入 *号表示选择加法 |\n”);
printf(“|输入 /号表示选择加法 |\n”);
printf(“|输入00表示结束 |\n”);
printf(“–/\n”);
printf(“请输入你想要的运算:”);
}
void Add()//加法块
{
printf(“运行加法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d+%d=”,a,b);
c=a+b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void Red()//减法块
{
printf(“运行减法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d-%d=”,a,b);
c=a-b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void Take()//乘块
{
printf(“运行乘法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d×%d”,a,b);
c=a*b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void Shang()//除法块
{
printf(“运行除法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d÷%d=”,a,b);
c=a/b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void ShuRu()
{
scanf(“%c”,&ch);
if(ch==””+””)
Add();
if(ch==””-“”)
Red();
if(ch==””*””)
Take();
if(ch==””/””)
Shang();
}
int main()
{
ShuoMing();
ShuRu();
jj:if(JieGuo==00)
{
printf(“程序结束,%d个正确。”,Lv);
getch();
printf(“按任意键结束。Bye Myqq2196760287\n”);
exit(0);
}
if(ch==””+””)
{
Add();
}
if(ch==””-“”)
{
Red();
}
if(ch==””*””)
{
Take();
}
if(ch==””/””)
{
Shang();
}
goto jj;
}
#include<time.h>
int a,b,c,ch,JieGuo,Lv;
void ShuoMing()
{
printf(“–程序说明–/\n”);
printf(“|输入 +号表示选择加法 |\n”);
printf(“|输入 -号表示选择加法 |\n”);
printf(“|输入 *号表示选择加法 |\n”);
printf(“|输入 /号表示选择加法 |\n”);
printf(“|输入00表示结束 |\n”);
printf(“–/\n”);
printf(“请输入你想要的运算:”);
}
void Add()//加法块
{
printf(“运行加法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d+%d=”,a,b);
c=a+b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void Red()//减法块
{
printf(“运行减法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d-%d=”,a,b);
c=a-b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void Take()//乘块
{
printf(“运行乘法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d×%d”,a,b);
c=a*b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void Shang()//除法块
{
printf(“运行除法运算:\n”);
srand(time(0));
a=rand()%10;
b=rand()%10;
printf(“%d÷%d=”,a,b);
c=a/b;
scanf(“%d”,&JieGuo);
if(JieGuo==c)
{
printf(“计算正确\n”);
Lv=Lv++;
}
else if(JieGuo!=00)
{
printf(“计算错误\n”);
}
}
void ShuRu()
{
scanf(“%c”,&ch);
if(ch==””+””)
Add();
if(ch==””-“”)
Red();
if(ch==””*””)
Take();
if(ch==””/””)
Shang();
}
int main()
{
ShuoMing();
ShuRu();
jj:if(JieGuo==00)
{
printf(“程序结束,%d个正确。”,Lv);
getch();
printf(“按任意键结束。Bye Myqq2196760287\n”);
exit(0);
}
if(ch==””+””)
{
Add();
}
if(ch==””-“”)
{
Red();
}
if(ch==””*””)
{
Take();
}
if(ch==””/””)
{
Shang();
}
goto jj;
}
解决方案:30分
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
int right;
void Menu();//菜单说明
void Calculation_formula();//随机生成运算式
void swap(int *a,int *b);//交换数值
void reverse(char str[],int n);//数组逆转
int main()
{
int number=0,accepted=0;
//number是总的测试题数,accepted是正确题数
int i,length,true_result;
char result[5];
Menu();
while(1){
i=0;
true_result=0;
Calculation_formula();
scanf("%s",result);//以数字字符数组形式保存输入的结果
if(result[1]==""0""&&result[0]==""0"")//结束标志
break;
length=strlen(result);
reverse(result,length);
while(result[i]!=""\0""){//将数字字符串转换成对应数值
true_result+=(result[i]-48)*pow(10,i);
i++;
}
if(true_result==right){
accepted++;
printf("计算正确!\n");
}
else{
printf("计算错误!正确结果是:%d\n",right);
}
number++;
fflush(stdin);
}
printf("测试结束!\n共%d道题目,通过%d道!\n",number,accepted);
return 0;
}
void Menu()//菜单说明
{
printf("\n\n");
printf("\t --程序说明--\n");
printf("\t| 输入+号表示选择加法 |\n");
printf("\t| 输入-号表示选择减法 |\n");
printf("\t| 输入*号表示选择乘法 |\n");
printf("\t| 输入/号表示选择除法 |\n");
printf("\t| 输入00表示结束程序 |\n");
printf("\t --\n");
printf("测试开始:\n");
}
void Calculation_formula()//运算式生成
{
int temp1,temp2;//保存随机生成的运算数
char c;//保存运算符
int temp;//随机生成0-3表示相应运算符
srand((unsigned)time(NULL));//将当前时间设为随机函数种子
temp=rand()%4;
temp1=rand()%10;
temp2=rand()%10;
switch (temp){
case 0://加法
c=""+"";
right=temp1+temp2;
break;
case 1://减法
c=""-"";
if(temp1<temp2)//结果非负
swap(&temp1,&temp2);
right=temp1-temp2;
break;
case 2://乘法
c=""*"";
right=temp1*temp2;
break;
case 3://除法
c=""/"";
if(temp1==0&&temp2==0){//两运算数不能都是0
do{
temp1=rand()%10;
temp2=rand()%10;
}while(temp1||temp2);
}
if(temp1<temp2)//被除数应不小于除数
swap(&temp1,&temp2);
if(temp2==0||temp1%temp2){//除数不能是0且相除不能有余数
do{
temp2=rand()%10;
}while(!temp2||(temp1%temp2));
}
right=temp1/temp2;
break;
}
printf("%d%c%d=",temp1,c,temp2);
}
void swap(int *a,int *b)//交换数值
{
int p=*a;
*a=*b;
*b=p;
}
void reverse(char str[],int n)//将数组逆转
{
char c;
int i;
for(i=0;i<n/2;i++){
c=str[i];
str[i]=str[n-i-1];
str[n-i-1]=c;
}
}
解决方案:30分
仅供参考:
//运用C语言开发一个“小学生算术四则运算测试系统”。该系统是让计算机充当一位给小学生布置作业的算术老师,为学生出题并阅卷。该系统要求实现下列功能:
//①为小学生出题(分别进行+、-、*、/等不同运算)。
//②学生做题后,进行评阅。学生每做一题后,评阅给出“答题正确,很好”或“答题错误,重做”等信息。
//③加、减、乘、除运算功能可以自由选择实现。
//④运算数值可控制在两位数的四则运算范围内。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int c,a,b,r,ri;
void main() {
srand( (unsigned)time( NULL ) );
system("cls");
printf("小学生算术四则运算测试系统\n");
while (1) {
printf("1加法 2减法 3乘法 4除法 0退出:");fflush(stdout);
rewind(stdin);
scanf("%d",&c);
if (0==c) break;
switch (c) {
case 1:
a=rand()%100;
b=rand()%100;
r=a+b;
while (1) {
printf("%d+%d=?",a,b);fflush(stdout);
rewind(stdin);
scanf("%d",&ri);
if (ri==r) {
printf("答题正确,很好!\n");
break;
} else {
printf("答题错误,请重做。\n");
}
}
break;
case 2:
a=1+rand()%99;
b=rand()%a;
r=a-b;
while (1) {
printf("%d-%d=?",a,b);fflush(stdout);
rewind(stdin);
scanf("%d",&ri);
if (ri==r) {
printf("答题正确,很好!\n");
break;
} else {
printf("答题错误,请重做。\n");
}
}
break;
case 3:
a=rand()%99;
b=rand()%99;
r=a*b;
while (1) {
printf("%d*%d=?",a,b);fflush(stdout);
rewind(stdin);
scanf("%d",&ri);
if (ri==r) {
printf("答题正确,很好!\n");
break;
} else {
printf("答题错误,请重做。\n");
}
}
break;
case 4:
a=2+rand()%998;
b=1+rand()%(a/2);
while (1) {
if (0==a%b) break;
b--;
}
r=a/b;
while (1) {
printf("%d/%d=?",a,b);fflush(stdout);
rewind(stdin);
scanf("%d",&ri);
if (ri==r) {
printf("答题正确,很好!\n");
break;
} else {
printf("答题错误,请重做。\n");
}
}
break;
}
}
}