201306114357-Experimental 3-c language

Source: Internet
Author: User

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Main ()
{
int a,b,c,n,u,i,sum;
int resulttrue=0;
int answer;
int time;
Char op,op2;
do//Generating Random numbers
{
A=rand ()%100+1;
B=rand ()%100+1;
C=rand ()%100+1;
N=rand ()%4+1;
U=rand ()%4+1;
Switch (n)
{
Case 1://contains an operator
{
Switch (u%4)//Generation operator
{
Case 0:
{
op= ' + ';
Break
}
Case 1:
{
op= '-';
Break
}
Case 2:
{
op= ' * ';
Break
}
Case 3:
{
op= '/';
Break
}
}
printf ("%d%c%d=\n", a,op,b);//Print
Switch (OP)//Calculate answer by operator
{
Case ' + ':
{
Resulttrue=a+b;
Break
}
Case '-':
{
Resulttrue=a-b;
Break
}
Case ' * ':
{
Resulttrue=a*b;
Break
}
Case '/':
{
resulttrue=a/b;
Break
}
}
while (time<121)
{
printf ("Please enter the correct answer (time is two minutes):");
scanf ("%d", &answer);
if (time==120)
{
printf ("Time is up, can't answer \ n");
time=0;
Break
}
if (time<120)
{
if (answer==resulttrue)
{
printf ("Correct answer \ n");
Break
}
Else
{
printf ("Wrong answer \ n");
Break
}
}
}
}
Case 2://produces two operators
{
Switch (u%4)//The first operator produces a
{
Case 0:
{
op= ' + ';
Break
}
Case 1:
{
op= '-';
Break
}
Case 2:
{
op= ' * ';
Break
}
Case 3:
{
op= '/';
Break
}
}
Switch (u%4)//The second operator produces
{
Case 0:
{
Op2= ' + ';
Break
}
Case 1:
{
Op2= '-';
Break
}
Case 2:
{
op2= ' * ';
Break
}
Case 3:
{
op2= '/';
Break
}
}
printf ("%d%c%d%c%d=\n", a,op,b,op,c);//Print
Switch (OP)//Calculate the answer first by calculating the first operator
{
Case ' + ':
{
Sum=a+b;
Break
}
Case '-':
{
Sum=a-b;
Break
}
Case ' * ':
{
Sum=a*b;
Break
}
Case '/':
{
sum=a/b;
Break
}
}
Switch (OP2)//And then based on the second operator
{
Case ' + ':
{
Sum=sum+c;
Break
}
Case '-':
{
Sum=sum-c;
Break
}
Case ' * ':
{
Sum=sum*c;
Break
}
Case '/':
{
SUM=SUM/C;
Break
}
}
while (time<123)//Time setting
{
printf ("Please enter the correct answer (time is two minutes):");
scanf ("%d", &answer);
if (time==120)
{
printf ("Time is up, can't answer \ n");
time=0;
Break
}
if (time<120)
{
if (answer==sum)
{
printf ("Correct answer \ n");
Break
}
Else
{
printf ("Wrong answer \ n");
Break
}
}
}
}
}
}while (1);
}


201306114357-Experimental 3-c language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.