• 实验一


    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    #define N 10 //题目数量
    main()
    {
    clock_t start = clock();
    char opChar;
    int a,b,user,system;
    int op;
    int i,rightType,wrongType;
    int rightNumber=0;
    int flag=0;

    srand(time(NULL));
    do{
    for(i=0;i<N;i++)
    {
    a=rand()%10+1;
    b=rand()%10+1;
    op=rand()%4+1;
    rightType=rand()%4+1;
    wrongType=rand()%4+1;
    switch(op)
    {
    case 1:
    opChar='+';
    system=a+b;
    break;
    case 2:
    opChar='-';
    system=a-b;
    break;
    case 3:
    opChar='*';
    system=a*b;
    break;
    case 4:
    opChar='/';
    system=a/b;
    break;
    default:
    printf("Unknown operator!");
    }
    printf("%d%c%d= ? ",a,opChar,b);
    scanf("%d",&user);
    if(user==system)
    {
    switch(rightType)
    {
    case 1:
    printf(" very good! ");
    break;
    case 2:
    printf(" excellent! ");
    break;
    case 3:
    printf(" nice work! ");
    break;
    case 4:
    printf(" keep up the good work! ");
    break;
    default:
    printf(" WrongType!");
    }
    rightNumber++;
    }
    else
    {
    printf(" wrong type! ");
    }
    }
    printf(" Total score is %d ",rightNumber*N);
    printf(" Rate of correnctness is %d %% ",rightNumber*N);
    if(rightNumber*N<75)
    {
    printf(" once again! ");
    rightNumber=0;
    flag=1;
    }
    }while(flag);
    clock_t finish = clock();
    double duration = (double)(finish - start) / CLOCKS_PER_SEC;
    printf(" 总共用时:");
    printf( " %f seconds ", duration );
    }

  • 相关阅读:
    批处理中的符号
    IF命令详解
    批处理介绍
    批处理中的变量
    单调栈2289. 使数组按非递减顺序排列
    01BFS2290. 到达角落需要移除障碍物的最小数目
    电脑FQ成功后,命令行无法FQ
    d365 webresource 批量更新
    asp.net mvc传值方式
    SpringBoot整合Nacos实现动态配置数据源
  • 原文地址:https://www.cnblogs.com/case1/p/4368174.html
Copyright © 2020-2023  润新知