#include <stdio.h>#include<stdlib.h>#include<time.h>inta[ -],b[ -];Charc[ -],sym[5]={'+','-','*','/','!'};intAnswerinti);voidPrintanswer (intn);voidMain () {intN,o,count; time_t start,end; inti; CharR; Srand ((unsigned) time (NULL)); while(1) {Count=0; printf ("Enter the number of required topics (0 exit):"); scanf ("%d",&N); if(n==0) Exit (0); Start=Time (NULL); for(i=0; i<n;i++) {A[i]=rand ()%201- -; B[i]=rand ()%201- -; C[i]=sym[rand ()%5]; if(c[i]==sym[4]) { while(a[i]<=0) {A[i]=rand ()%201- -; } printf ("%d!=", A[i]); } Else if(a[i]<0&&b[i]<0) printf ("(%d)%c (%d) =", A[i],c[i],b[i]); Else if(a[i]<0&&b[i]>0) printf ("(%d)%c%d=", A[i],c[i],b[i]); Else if(a[i]>0&&b[i]<0) printf ("%d%c (%d) =", A[i],c[i],b[i]); Elseprintf"%d%c%d=", A[i],c[i],b[i]); scanf ("%d",&o); if(o==Answer (i)) {printf ("correct!\n"); Count++; } Elseprintf"the answer is%d\n.", Answer (i)); } End=Time (NULL); printf ("Correct the%d question, answer the wrong question%d,", count,n-count); printf ("elapsed time is%d seconds \ n", end-start); }}intAnswerinti) { into; if(c[i]==sym[0]) o=a[i]+B[i]; if(c[i]==sym[1]) o=a[i]-B[i]; if(c[i]==sym[2]) o=a[i]*B[i]; if(c[i]==sym[3]) o=a[i]/B[i]; if(c[i]==sym[4]) {o=A[i]; for(i=a[i];i>0; i--) o=o* (o1); } returno;}
Assignment 2 pair Arithmetic