• 第三次作业


    作业地址:https://edu.cnblogs.com/campus/nenu/2016CS/homework/2266

    coding地址:https://coding.net/u/e1209548561/p/f4/attachment

    没找到组。。。。单出来了,所以我没有体会

    代码如下:

      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<string.h> 
      4 #include<time.h>
      5 #include<math.h>
      6 /*#define path D:\test.txt 
      7 int main(int argc,char* argv[]) 
      8 {char a[2]={'-','c'};
      9 if(strcmp(a,argv[0])==0)
     10     {*/
     11 int main()
     12 {
     13 
     14     double n,answer,youranswer,num1,num2,num3,num4;
     15     int n1,n2,n3,n4,om1,om2,om3,m=0;
     16     char oper[4]={'+','-','*','/'};
     17     char wenhao;
     18     scanf("%lf",&n);
     19     if(n!=(int)n)
     20         {
     21             printf("题目数量必须是 正整数。");
     22         }
     23     else
     24         {
     25                 srand(time(0));
     26             for(int i=0;i<n;i++)
     27             {
     28             
     29                 n1=rand()%10+1;
     30                 num1=n1*1.0;
     31                 n2=rand()%10+1;
     32                 num2=n2*1.0;
     33                 n3=rand()%10+1;
     34                 num3=n3*1.0;
     35                 n4=rand()%10+1;
     36                 num4=n4*1.0;
     37                 om1=rand()%4;
     38                 om2=rand()%4;
     39                 om3=rand()%4;
     40                 printf(" %d %c %d %c %d %c %d
    ",n1,oper[om1],n2,oper[om2],n3,oper[om3],n4);
     41                 
     42      if((om1==0)&&(om2==0)&&(om3==0)) {answer=num1+num2+num3+num4;}
     43 else if((om1==0)&&(om2==0)&&(om3==1)) {answer=num1+num2+num3-num4;}
     44 else if((om1==0)&&(om2==0)&&(om3==2)) {answer=num1+num2+num3*num4;}
     45 else if((om1==0)&&(om2==0)&&(om3==3)) {answer=num1+num2+num3/num4;}
     46 
     47 else if((om1==0)&&(om2==1)&&(om3==0)) {answer=num1+num2-num3+num4;}
     48 else if((om1==0)&&(om2==1)&&(om3==1)) {answer=num1+num2-num3-num4;}
     49 else if((om1==0)&&(om2==1)&&(om3==2)) {answer=num1+num2-num3*num4;}
     50 else if((om1==0)&&(om2==1)&&(om3==3)) {answer=num1+num2-num3/num4;}
     51 
     52 else if((om1==0)&&(om2==2)&&(om3==0)) {answer=num1+num2*num3+num4;}
     53 else if((om1==0)&&(om2==2)&&(om3==1)) {answer=num1+num2*num3-num4;}
     54 else if((om1==0)&&(om2==2)&&(om3==2)) {answer=num1+num2*num3*num4;}
     55 else if((om1==0)&&(om2==2)&&(om3==3)) {answer=num1+num2*num3/num4;}
     56 
     57 else if((om1==0)&&(om2==3)&&(om3==0)) {answer=num1+num2/num3+num4;}
     58 else if((om1==0)&&(om2==3)&&(om3==1)) {answer=num1+num2/num3-num4;}
     59 else if((om1==0)&&(om2==3)&&(om3==2)) {answer=num1+num2/num3*num4;}
     60 else if((om1==0)&&(om2==3)&&(om3==3)) {answer=num1+num2/num3/num4;}
     61 ////////////
     62 else if((om1==1)&&(om2==0)&&(om3==0)) {answer=num1-num2+num3+num4;}
     63 else if((om1==1)&&(om2==0)&&(om3==1)) {answer=num1-num2+num3-num4;}
     64 else if((om1==1)&&(om2==0)&&(om3==2)) {answer=num1-num2+num3*num4;}
     65 else if((om1==1)&&(om2==0)&&(om3==3)) {answer=num1-num2+num3/num4;}
     66 
     67 else if((om1==1)&&(om2==1)&&(om3==0)) {answer=num1-num2-num3+num4;}
     68 else if((om1==1)&&(om2==1)&&(om3==1)) {answer=num1-num2-num3-num4;}
     69 else if((om1==1)&&(om2==1)&&(om3==2)) {answer=num1-num2-num3*num4;}
     70 else if((om1==1)&&(om2==1)&&(om3==3)) {answer=num1-num2-num3/num4;}
     71 
     72 else if((om1==1)&&(om2==2)&&(om3==0)) {answer=num1-num2*num3+num4;}
     73 else if((om1==1)&&(om2==2)&&(om3==1)) {answer=num1-num2*num3-num4;}
     74 else if((om1==1)&&(om2==2)&&(om3==2)) {answer=num1-num2*num3*num4;}
     75 else if((om1==1)&&(om2==2)&&(om3==3)) {answer=num1-num2*num3/num4;}
     76 
     77 else if((om1==1)&&(om2==3)&&(om3==0)) {answer=num1-num2/num3+num4;}
     78 else if((om1==1)&&(om2==3)&&(om3==1)) {answer=num1-num2/num3-num4;}
     79 else if((om1==1)&&(om2==3)&&(om3==2)) {answer=num1-num2/num3*num4;}
     80 else if((om1==1)&&(om2==3)&&(om3==3)) {answer=num1-num2/num3/num4;}
     81 /////////////////
     82 else if((om1==2)&&(om2==0)&&(om3==0)) {answer=num1*num2+num3+num4;}
     83 else if((om1==2)&&(om2==0)&&(om3==1)) {answer=num1*num2+num3-num4;}
     84 else if((om1==2)&&(om2==0)&&(om3==2)) {answer=num1*num2+num3*num4;}
     85 else if((om1==2)&&(om2==0)&&(om3==3)) {answer=num1*num2+num3/num4;}
     86 
     87 else if((om1==2)&&(om2==1)&&(om3==0)) {answer=num1*num2-num3+num4;}
     88 else if((om1==2)&&(om2==1)&&(om3==1)) {answer=num1*num2-num3-num4;}
     89 else if((om1==2)&&(om2==1)&&(om3==2)) {answer=num1*num2-num3*num4;}
     90 else if((om1==2)&&(om2==1)&&(om3==3)) {answer=num1*num2-num3/num4;}
     91 
     92 else if((om1==2)&&(om2==2)&&(om3==0)) {answer=num1*num2*num3+num4;}
     93 else if((om1==2)&&(om2==2)&&(om3==1)) {answer=num1*num2*num3-num4;}
     94 else if((om1==2)&&(om2==2)&&(om3==2)) {answer=num1*num2*num3*num4;}
     95 else if((om1==2)&&(om2==2)&&(om3==3)) {answer=num1*num2*num3/num4;}
     96 
     97 else if((om1==2)&&(om2==3)&&(om3==0)) {answer=num1*num2/num3+num4;}
     98 else if((om1==2)&&(om2==3)&&(om3==1)) {answer=num1*num2/num3-num4;}
     99 else if((om1==2)&&(om2==3)&&(om3==2)) {answer=num1*num2/num3*num4;}
    100 else if((om1==2)&&(om2==3)&&(om3==3)) {answer=num1*num2/num3/num4;}
    101 /////////////////
    102 else if((om1==3)&&(om2==0)&&(om3==0)) {answer=num1/num2+num3+num4;}
    103 else if((om1==3)&&(om2==0)&&(om3==1)) {answer=num1/num2+num3-num4;}
    104 else if((om1==3)&&(om2==0)&&(om3==2)) {answer=num1/num2+num3*num4;}
    105 else if((om1==3)&&(om2==0)&&(om3==3)) {answer=num1/num2+num3/num4;}
    106 
    107 else if((om1==3)&&(om2==1)&&(om3==0)) {answer=num1/num2-num3+num4;}
    108 else if((om1==3)&&(om2==1)&&(om3==1)) {answer=num1/num2-num3-num4;}
    109 else if((om1==3)&&(om2==1)&&(om3==2)) {answer=num1/num2-num3*num4;}
    110 else if((om1==3)&&(om2==1)&&(om3==3)) {answer=num1/num2-num3/num4;}
    111 
    112 else if((om1==3)&&(om2==2)&&(om3==0)) {answer=num1/num2*num3+num4;}
    113 else if((om1==3)&&(om2==2)&&(om3==1)) {answer=num1/num2*num3-num4;}
    114 else if((om1==3)&&(om2==2)&&(om3==2)) {answer=num1/num2*num3*num4;}
    115 else if((om1==3)&&(om2==2)&&(om3==3)) {answer=num1/num2*num3/num4;}
    116 
    117 else if((om1==3)&&(om2==3)&&(om3==0)) {answer=num1/num2/num3+num4;}
    118 else if((om1==3)&&(om2==3)&&(om3==1)) {answer=num1/num2/num3-num4;}
    119 else if((om1==3)&&(om2==3)&&(om3==2)) {answer=num1/num2/num3*num4;}
    120 else {answer=num1/num2/num3/num4;}
    121             //    scanf("%c",&wenhao);
    122         
    123                 scanf("%lf",&youranswer);
    124                 if(answer==youranswer)
    125                 {
    126                     printf("回答正确。
    ");
    127                     m++;
    128                 }
    129                 else
    130                 printf("回答错误,正确答案是%0.3f。
    ",answer);
    131             }
    132             printf("总共%0.0f道题,你答对%d道题。",n,m);
    133         }
    134     
    135 }
  • 相关阅读:
    Hello World
    查找字符串 fiand
    stdou,write与print()
    python 中 按位 与 & ,| ,^ ,~,
    3*3元素主对角元素之和
    Python random() 函数
    文本颜色设计
    if __name__=="__main__
    join函数
    ProGAN论文的翻译+学习体会
  • 原文地址:https://www.cnblogs.com/huangl816/p/9932876.html
Copyright © 2020-2023  润新知