• 自动生成的四则运算


    源程序:

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    void main()
    {
    int a,b,c,d;
    int total1=0,total2=0;
    while(1)
    {
    srand(time(NULL));
    d=a=rand()%10;
    b=(rand()%a+a)%10;
    if(a%4==1&&a<b)c=a,a=b,b=c;
    if(b==0&&a%4==3)b=rand()%10+1;
    if(a%4==3&&a%b!=0)
    {
    srand(time(0));
    a=b*(rand()%a);
    }
    switch(d%4)
    {
    case 0:printf("%d + %d = ",a,b);break;
    case 1:printf("%d - %d = ",a,b);break;
    case 2:printf("%d × %d = ",a,b);break;
    case 3:printf("%d ÷ %d = ",a,b);break;
    }
    scanf("%d",&c);
    switch(d%4)
    {
    case 0:if(c==a+b)
    {
    printf("正确\n");total1++;
    }
    else
    {
    printf("错误\n");total2++;
    }
    break;
    case 1:if(c==a-b)
    {
    printf("正确\n");total1++;
    }
    else
    {
    printf("错误\n");total2++;
    }
    break;
    case 2:if(c==a*b)
    {
    printf("正确\n");total1++;
    }
    else
    {
    printf("错误\n");total2++;
    }
    break;
    case 3:if(c==a/b)
    {
    printf("正确\n");total1++;
    }
    else
    {
    printf("错误\n");total2++;
    }
    break;
    }
    printf("按任意键继续,Q退出!\n");
    fflush(stdin);
    if(getchar()=='Q')break;
    }
    printf("你答对了%d道题,答错%d道题\n",total1,total2);
    }

    感想:本程序只实现了加、减、乘、除四个基本运算,像括号啊,分数啊,小数点这些都没搞定,虽然程序完成的不是很好,但起码基本的功能是有的!

  • 相关阅读:
    [装]JMX监控Hadoop
    [转]JMX的Hello World
    [转]Linux下查看CPU信息、机器型号等硬件信息
    [转] pom.xml 配置详解
    HBase TableExistsException: hbase:namespace
    [转]HBase高可用性的新阶段
    [转]Hadoop 读写数据流
    HBase——强一致性详解
    HBase Master高可用(HA)
    Hadoop HA on Yarn——集群启动
  • 原文地址:https://www.cnblogs.com/cjj19/p/4363474.html
Copyright © 2020-2023  润新知