第九周 小学生数学考试系统

来源:互联网 发布:mac系统能玩什么游戏 编辑:程序博客网 时间:2024/04/29 17:55

烟台大学 计算机控制与工程学院

作者:单长喜

题目描述:随机出十道题。

程序:

#include <stdio.h>#include <stdlib.h>#include <time.h>int main(){    int i,j,n,a,b,c,d,e;    n=0;    srand(time(0));    for(i=1; i<=10; i++)    {        j=rand()%4;        do        {            a=rand()%100+1;            b=rand()%100+1;            if(a<b&&(j==2||j==0))            {                e=b;                b=a;                a=e;            }            if(j==0)                a=(a/b)*b;        } while(a+b>=100||a*b>=100);        if(j==1)        {            c=a+b;            printf("%d+%d=",a,b);        }        else if(j==2)        {            c=a-b;            printf("%d-%d=",a,b);        }         else if(j==3)        {            c=a*b;            printf("%d*%d=",a,b);        }        else        {            c=a/b;            printf("%d/%d=",a,b);        }        scanf("%d",&d);        if(c==d)        {            printf("Yes!\n");            n++;        }        else            printf("NO!\n");    }    printf("共答对%d道题",n);    return 0;}

结果:


0 0
原创粉丝点击