代码如下,测试可运行,不过没蜂鸣就是了
#include
#include
#include
int question(int number)//100以内的加减法
{
int i,j,k,answer,realAnswer;//i,j为被加被减数,k为运算符(通过模2)
char opper;
srand((unsigned)time(NULL));
i=rand()%100;
j=rand()%100;
k=rand()%2;
if(k) opper='+';
else opper='-';
if(i
int temp;
temp=i;
i=j;
j=temp;
}
if(opper=='+')
realAnswer=i+j;
else
realAnswer=i-j;
printf("No.%d: %d%c%d=",number,i,opper,j);
scanf("%d",&answer);
if(answer==realAnswer)
return 1;//正确则返回1
else
{
printf("答案错误,正确答案为%d\n",realAnswer);
return 0;
}
}
int main()
{
int number,i,rightNum=0,wrongNum=0;
float score;
printf("请输入题目个数:\n");
scanf("%d",&number);
i=number;
while(i)
{
rightNum+=question(number-i+1);
i--;
}
wrongNum=number-rightNum;
score=100*((float)rightNum/(float)number);
printf("算对%d题,算错%d题,总得分为%.2f\n",rightNum,wrongNum,score);
system("pause");
}
我的可以计算,加减乘除。自选。 计算的最大值100 可以自选。默认是0-50以内。可以自己设置。
你是要代码? 还是要可以直接运行的程序?
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
struct timu
{
int num1;
int num2;
char fuhao;
int right;
int yu;
int yu_r;
int daan;
}std[5];
main()
{
int i,n=0,cj=0;
char fh[4]="+-*/";
system("cls");
srand((unsigned long)time(0));
for(i=0;i<5;i++)
{
std[i].num1=rand()%100;
std[i].num2=rand()%100;
std[i].fuhao=fh[rand()%4];
while((std[i].fuhao=='/')&&((std[i].num2==0)||(std[i].num2>std[i].num1)))
{
std[i].num2=rand()%100;
}
while(std[i].fuhao=='-'&&std[i].num2>std[i].num1)
{
std[i].num2=rand()%100;
}
printf("%d %c %d = ",std[i].num1,std[i].fuhao,std[i].num2);
switch(std[i].fuhao)
{
case '+':std[i].right=std[i].num1+std[i].num2;break;
case '-':std[i].right=std[i].num1-std[i].num2;break;
case '*':std[i].right=std[i].num1*std[i].num2;break;
case '/':std[i].right=std[i].num1/std[i].num2;std[i].yu=std[i].num1%std[i].num2;break;
}
if((std[i].fuhao=='/')&&(std[i].yu!=0))
scanf("%d%d",&std[i].daan,&std[i].yu_r);
else
{
std[i].yu_r=0;
scanf("%d",&std[i].daan);
}
if(std[i].daan==std[i].right&&std[i].yu==std[i].yu_r)
n++;
cj=n*10;
printf("\n当前成绩:%d\n\n",cj);
}
printf("\n\n总成绩:%d\n",cj);
for(i=0;i<5;i++)
{
if((std[i].fuhao=='/')&&(std[i].yu!=0))
printf("\n%d. %d %c %d = %d %d\n\t您的答案:d %d\n",i+1,std[i].num1,std[i].fuhao,std
[i].num2,std[i].right,std[i].yu_r,std[i].daan,std[i].yu);
else
printf("\n%d. %d %c %d = %d\n\t您的答案:%d\n",i+1,std[i].num1,std[i].fuhao,std[i].num2,std
[i].right,std[i].daan);
}
getch();
}