Classroom Test Small Program

Source: Internet
Author: User

Title: Arithmetic of random numbers

Idea: Take two random integers, put the operation symbol in an array, then take a random number, divide by 4, and select the budget symbol by the remainder. The arithmetic of a true fraction is to take four random integers, and to determine the size, the denominator of the true fraction is greater than its numerator.

Code:

#include <iostream>
#include <time.h>
using namespace Std;
void Main ()
{
Srand (Time (NULL));
for (int i = 1; i <=; i++)
{
int a = rand ()%25+1;
int b = rand ()%25+1;
int c = rand ()% 25 + 1;
int d = rand ()% 25 + 1;
int e = a% 2;
int f = b% 4;
int x[4] = {' + ', '-', ' * ', '/'};
int y = 0;
if (e = = 1 && b < a&&d < C)
{
if (f = = 1)

cout << b << '/' << a << ' << ' + ' << ' << d << '/' << C << "=" << Endl;

else if (f = = 2)

cout << b << '/' << a << ' << '-' << ' << d << '/' << C << "=" << Endl;

else if (f = = 3)

cout << b << '/' << a << ' << ' * ' << ' << d << '/' << C << "=" << Endl;

Else

cout << b << '/' << a << ' << '/' << ' << d << '/' << C << "=" << Endl;
}

Else
{
if (f = = 1)
{
y = a + b;
cout << a << ' + ' << b << "=" << Endl;
}
else if (f = = 2)
{
y = a-B;
cout << a << '-' << b << ' = ' << Endl;
}
else if (f = = 3)
{
y = a * b;
cout << a << ' * ' << b << "=" << Endl;
}
Else
{
y = b/a;
cout << b << '/' << a << ' = ' << Endl;
}
}

}
}

Feel: Through this little test, I understand the importance of the idea of "decomposition".

Classroom Test Small Program

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.