• 小学四则运算


    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    int question_get();
    int type;
    void main( void )
    {
     int answer,n;
     srand( (unsigned)time( NULL ) );
     
    loop:  printf( "请选择要进行测试的题目种类:" );
       
        printf( "\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n" );
       
        printf("\t\t\t请选择(1-5):");
       
        scanf( "%d", &type );
       
        while( 1 )
        {  
         int temp;
         int flag;
         answer = question_get();
         printf( "请回答:\n" );
         scanf( "%d", &temp );
         while( temp!=answer )
         {
          printf( "\n答案错误,重做\n" );
          scanf( "%d", &temp );
         }
         printf( "\n答案正确,很好\n" );
        
         printf( "继续请按1,退出请按0\n" );
               scanf( "%d", &flag );
        
         while( flag!=0&&flag!=1 )
         
         {
          printf( "按其它键无效\n" );
          scanf( "%d", &flag );
         }
         if( flag==0 )
          break;
        
         goto loop;
        
        
        }
    }
    int question_get()
    {
     int a,b,c;
    loop: if( type==1 )
       {
        a=rand()%99;
        b=99-a;
        b=rand()%b;
        printf( "%d + %d = ?", a, b );
        return(a+b);
          }
       else if( type==2 )
       {
        b=rand()%99;
        c=99-b;
        c=rand()%c;
        printf( "%d - %d = ?", b+c, b );
        return(c);
          }
       else if( type==3 )
       {
        a=rand()%10;
        b=50-a;
        b=rand()%b;
        printf( "%d * %d = ?", a, b );
        return(a*b);
          }
       else if( type==4 )
       {
        b=rand()%50;
        c=100/b;
        while( 1 )
        {
         c=rand()%c;
         if( c!=0 )
          break;
        }
        printf( "%d / %d = ?", b*c, b );
        return(c);
          } 
       else if( type==5 )
       {
        printf("\t\t\t退出系统\n"); /*结束程序*/
        system("pause");
        exit(0);
          }
       else if( type==0||type>5 )
          {
        printf("\t\t\t输入错误,请输入1-5内的数字\n");
        printf("\t\t\t请选择(1-5):");
        scanf( "%d", &type );
        goto loop;
       }
    }

  • 相关阅读:
    Struts2拦截器defaultStack与paramsPrepareParamsStack
    Java中的数据类型BigDecimal
    JfreeChart报表数据点显示、链接
    JPA+Hibernate3 CRUD(增删改查操作)
    Ibatis的批量处理iterateiterate标签
    .net中split的用法,asp.net字符分隔
    存储过程中RETURN语句的返回值
    SQL自定义函数学习修改和删除和管理
    SqlCommand 方法
    由于该计算机受到限制本次操作已被取消请与你的系统管理员联系
  • 原文地址:https://www.cnblogs.com/iliuh/p/4372725.html
Copyright © 2020-2023  润新知