标签:重复 bsp 避免 支持 cas 运算 四则运算 scan and
在原有四则运算基础上,除整数以外要支持真分数运算(验证正确性)
一次出的题避免相互重复
可定制出题数目
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,i,k;
printf("请输入题目数量:");
scanf("%d",&num);
float fa,fb,fc,fd,result;
k=0;
for (i=0; i<num; i++)
{
int isint1=rand()%2;
int isint2=rand()%2;
if (isint1==0)
{
fa=rand()%100+1;
}
else
{
fa=rand()%100+1;
fb=rand()%100+1;
if (fa>fb)
fa=fb/fa;
else
fa=fa/fb;
}
if (isint2==0)
{
fc=rand()%100+1;
}
else
{
fc=rand()%100+1;
fd=rand()%100+1;
if (fc>fd)
fc=fd/fc;
else
fc=fc/fd;
}
int op;
op=rand()%4;
switch(op)
{
case 0:
{
printf("%f + %f=",fa,fb);
scanf("%f",&result);
if (result-(fa+fb)<0.000001)
k++;
break;
}
case 1:
{
printf("%f - %f=",fa,fb);
scanf("%f",&result);
if (result-(fa-fb)<0.000001)
k++;
break;
}
case 2:
{
printf("%f * %f=",fa,fb);
scanf("%f",&result);
if (result-(fa*fb)<0.000001)
k++;
break;
}
case 3:
{
printf("%f / %f=",fa,fb);
scanf("%f",&result);
if (result-(fa/fb)<0.000001)
k++;
break;
}
}
}
printf("你一共算对了%d道题",k);
}
标签:重复 bsp 避免 支持 cas 运算 四则运算 scan and
原文地址:https://www.cnblogs.com/zzzzxiaolan/p/9748175.html