• 四则运算 最新修改版


    #include<stdio.h>
    #include<malloc.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    char fuhao()
    {

    int xuanzhe;
    time_t t;
    srand((unsigned)time(&t));
    xuanzhe=rand()%4+1;
    switch(xuanzhe)
    {
    case 1:return'+';
    case 2:return'-';
    case 3:return'*';
    case 4:return'/';
    }
    }
    void main()
    {
    float shuru3;
    time_t t;
    int geshu,fanwei,shuliang,shu1,shu2,defen,shuru,xuanzhe,shu3,shuliang1,xuanzhe2,fujiati,shu4;
    float b;
    char c,c1;
    char fenshu[10];
    static char fenshudaan[10];
    printf("*********************************************** ");
    printf("输入1:2个数 ");
    printf("输入2:3个数 ");
    printf("请输入四则数目的个数");
    scanf("%d",&geshu);
    while(geshu!=1||geshu!=2)
    {
    printf("*********************************************** ");
    printf("输入错误,请从新输入 ");
    printf("输入1:2个数 ");
    printf("输入2:3个数 ");
    printf("请输入:");
    scanf("%d",&geshu);
    }
    printf("请输入四则运算最大的数目(最好10-100):");
    scanf("%d",&fanwei);
    printf("请输入题目计算的数的最大量:");
    scanf("%d",&shuliang);
    if(geshu==1)
    {

    for(int i=1;i<=shuliang;i++)
    {
    c=fuhao();
    srand((unsigned)time(&t));
    shu1=rand()%fanwei+1;
    shu2=rand()%fanwei+1;
    if(c=='+')
    {defen=shu1+shu2;
    }
    else if(c=='-')
    {defen=shu1-shu2;
    }
    else if(c=='*')
    {defen=shu1*shu2;
    }
    else if(c=='/')
    {defen=shu1/shu2;
    }
    printf("第%d题:%d%c%d=",i,shu1,c,shu2);
    scanf("%d",&shuru);
    if(shuru==defen)
    {
    printf("正确! ");
    }
    else
    {
    printf("错误! ");
    }
    }
    }
    if(geshu==2)
    {
    for(int ii=1;ii<=shuliang;ii++)
    {
    srand((unsigned)time(&t));
    shu1=rand()%fanwei+1;
    shu2=rand()%fanwei+1;
    shu3=rand()%fanwei+1;
    shu4=rand()%16+1;

    switch(shu4)
    {
    case 1:c1='*';c='-';
    shuliang1=shu1*shu2-shu3;break;
    case 2:c1='*';c='+';
    shuliang1=shu1*shu2+shu3;break;
    case 3:c1='/';c='-';
    shuliang1=shu1/shu2-shu3;break;
    case 4:c1='/';c='+';
    shuliang1=shu1/shu2+shu3;break;
    case 5:c1='/';c='/';
    shuliang1=shu1/shu2/shu3;break;
    case 6:c1='/';c='*';
    shuliang1=shu1/shu2*shu3;break;
    case 7:c1='*';c='+';
    shuliang1=shu1*shu2+shu3;break;
    case 8:c1='*';c='*';
    shuliang1=shu1*shu2*shu3;break;
    case 9:c1='-';c='+';
    shuliang1=shu1-shu2+shu3;break;
    case 10:c1='-';c='-';
    shuliang1=shu1-shu2-shu3;break;
    case 11:c1='-';c='*';
    shuliang1=shu1-shu2*shu3;break;
    case 12:c1='-';c='/';
    shuliang1=shu1-shu2/shu3;break;
    case 13:c1='+';c='-';
    shuliang1=shu1+shu2-shu3;break;
    case 14:c1='+';c='+';
    shuliang1=shu1+shu2+shu3;break;
    case 15:c1='+';c='*';
    shuliang1=shu1+shu2*shu3;break;
    case 16:c1='+';c='/';
    shuliang1=shu1+shu2/shu3;break;
    }
    printf("第%d题:%d%c%d%c%d=",ii,shu1,c1,shu2,c,shu3);
    scanf("%d",&shuru);
    printf("%d",shuru);
    if(shuru==shuliang1)
    {
    printf("正确! ");
    }
    else
    {
    printf("错误! ");
    }
    }
    printf("是否做附加题(1:是。2:否。):");
    scanf("%d",&fujiati);
    if(fujiati==1)
    {
    srand((unsigned)time(&t));
    xuanzhe2=rand()%5+1;
    switch(xuanzhe2)
    {
    case 1:
    strcpy(fenshu,"2/3");
    printf("2/(4-1)=");
    scanf("%s",fenshudaan);


    break;
    case 2:
    printf("5/(13-1)=");
    strcpy(fenshu,"5/12 ");
    scanf("%s",fenshudaan);

    break;
    case 3:
    strcpy(fenshu,"3/7");
    printf("(1+2)/7=");
    scanf("%s",fenshudaan);

    break;

    case 4:
    strcpy(fenshu,"1/3");
    printf("(4-3)/3=");
    scanf("%s",fenshudaan);


    break;
    case 5:
    strcpy(fenshu,"21");
    printf("(4+3)*3=");
    scanf("%s",fenshudaan);
    break;

    }

    if(!strcmp(fenshu,fenshudaan))
    {
    printf("%s正确!",fenshudaan);
    }
    else
    {
    printf("%s错误!",fenshudaan);
    }

    }
    else
    {
    printf("程序结束!");
    exit(0);
    }

    printf("程序结束!");

    }
    }

    心得体会:修改了很多if-else语句,修改了某些bug,修改了某些表达不清晰的提示。

  • 相关阅读:
    在初次安vs2008时设置的为C#现在怎么将其改为其他类型的界面
    CREATEMUTEX
    ISO 18000-6c 访问标签--应用程序访问操作ISO 18000-6C标签的方法
    虚函数的特性
    关于命名空间
    ubuntu 卸载/安装 redis
    【分享】推荐一些不错的计算机书籍
    [转]十款提高开发效率的PHP编码工具
    当当网
    Yii框架第一步-- 安装
  • 原文地址:https://www.cnblogs.com/shaojiawen/p/4372543.html
Copyright © 2020-2023  润新知