Lab 3-2, Shenzhen middle school 32 experimental classes

Source: Internet
Author: User

Lab 3-2, Shenzhen middle school 32 experimental classes

# Include <stdio. h>
# Include <stdlib. h>
# Include <time. h>
Main ()
{
Int a, B, c, n, u, I, e = 0;
Int sum2 = 1;
Int sum = 0;
Float sum3 = 0;
Float answer2;
Int resultTrue = 0;
Int answer;
Int time = 0;
Char op, op2;
Do // generate a random number
{
A = rand () % 100 + 1;
B = rand () % 100 + 1;
C = rand () % 100 + 1;
N = rand () % 4 + 1;
U = rand () % 9 + 1;
E = rand () % 10 + 1;
Switch (n)
{
Case 1: // contains an operator
{
Switch (u % 4) // generate the 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 the answer using the operator
{
Case '+ ':
{
ResultTrue = a + B;
Break;
}
Case '-':
{
ResultTrue = a-B;
Break;
}
Case '*':
{
ResultTrue = a * B;
Break;
}
Case '/':
{
Sum3 = (float) a/B;
Printf ("enter the correct answer (two minutes ):");
Scanf ("% d", & answer2 );
If (sum3 = answer2)
{
Printf ("correct answer \ n ");
}
Else
{
Printf ("Incorrect answer \ n ");
Printf ("correct answer: % f \ n", sum3 );
}
Break;
}
}
While (time <1, 121)
{
Printf ("enter the correct answer (two minutes ):");
For (I = 0; I <121; I ++)
{
Time ++;
Scanf ("% d", & answer );
If (time = 120)
{
Printf ("time is up, cannot answer \ n ");
Time = 0;
Break;
}
If (time <1, 120)
{
If (answer = resultTrue)
{
Printf ("correct answer \ n ");
Printf ("the answer time is % d \ n", time );
Time = 0;
Break;
}
Else
{
Printf ("Incorrect answer \ n ");
Printf ("the answer is % d \ n", resultTrue );
Break;
}
}
}
}
}
Case 2: // generate two operators
{
Switch (u % 4) // The First operator is generated
{
Case 0:
{
Op = '+ ';
Break;
}
Case 1:
{
Op = '-';
Break;
}
Case 2:
{
Op = '*';
Break;
}
Case 3:
{
Op = '/';
Break;
}
}
Switch (u % 4) // produced by the second operator
{
Case 0:
{
Op2 = '+ ';
Break;
}
Case 1:
{
Op2 = '-';
Break;
}
Case 2:
{
Op2 = '*';
Break;
}
Case 3:
{
Op2 = '/';
Break;
}
}
Printf ("% d % c % d = \ n", a, op, B, op, c); // print
Switch (op) // calculate the answer first using the first operator
{
Case '+ ':
{
Sum = a + B;
Break;
}
Case '-':
{
Sum = a-B;
Break;
}
Case '*':
{
Sum = a * B;
Break;
}
Case '/':
{
Sum3 = (float) a/B;
Break;
}
}
Switch (op2) // then calculated based on the second operator
{
Case '+ ':
{
Sum = sum + c;
Break;
}
Case '-':
{
Sum = sum-c;
Break;
}
Case '*':
{
Sum = sum * c;
Break;
}
Case '/':
{
Sum3 = (float) sum3/c;
Printf ("enter the correct answer (two minutes ):");
Scanf ("% d", & answer2 );
If (sum3 = answer2)
{
Printf ("correct answer \ n ");
}
Else
{
Printf ("Incorrect answer \ n ");
Printf ("correct answer: % f \ n", sum3 );
}
Break;
}
}
While (time <123) // time setting
{
Printf ("enter the correct answer (two minutes ):");
For (I = 0; I <123; I ++)
{
Time ++;
Scanf ("% d", & answer );
If (time = 120)
{
Printf ("time is up, cannot answer \ n ");
Time = 0;
Break;
}
If (time <1, 120)
{
If (answer = sum)
{
Printf ("correct answer \ n ");
Printf ("Your Answer time is % d \ n", time );
Time = 0;
Break;
}
Else
{
Printf ("Incorrect answer \ n ");
Printf ("the answer is % d \ n", sum );
Break;
}
}
}
}
}
Case 3:
{
Printf ("Enter % d! = ", E );
Scanf ("% d", & answer );
For (I = 1; I <= e; I ++)
{
Sum2 = sum2 * I;
}
While (time <1, 121)
{
If (time = 120)
{
Time = 0;
Printf ("reached time \ n ");
Break;
}
If (time <1, 120)
{
If (answer = sum2)
{
Printf ("correct answer \ n ");
Printf ("% d \ n", time );
Sum2 = 1;
Break;
}
Else
{
Printf ("Incorrect answer \ n ");
Printf ("the answer is % d \ n", sum2 );
Sum2 = 1;
Break;
}
}
}
}
}
} While (1 );
}

Related Article

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.