Randomly generates 30 to integer true fraction arithmetic

Source: Internet
Author: User

This is the first code written in software engineering, the main idea is to use random numbers to produce integer true fractions and four of the numbers representing the operation symbols, the only complex point to determine whether the divisor is zero, integer operations using the method of re-generation of random numbers, the division of the real fractional operation is zero using the numerator denominator plus 1 method processing.

This procedure mainly uses the

RAND ()%100 generates random numbers
Srand ((int) time (NULL));

Write ideas in class time 30 minutes during the actual writing process through the online information to ask students to learn the above two code to write 1.5 hours.

#include <iostream>
#include <ctime>
#include <stdlib.h>
using namespace std;
int main ()
{
int num1, num2, sym;
Srand ((int) time (NULL));
for (int i = 1; i < i++)
{
Num1 = rand ()%;
num2 = rand ()% 100;
int k = rand ()% 2;
Sym = rand ()% 4;

if (k = = 1)//-------------------integer operation
{
if (sym = = 0)
{
cout << num1 << "+" << num2 << "=" << Endl;
}
if (sym = = 1)
{
cout << num1 << "-" << num2 << "=" << Endl;
}
if (sym = = 2)
{
cout << num1 << "*" << num2 << "=" << Endl;
}
if (sym = = 3)
{
if (num2 = = 0)
{
num2 = rand ()% + 1;
cout << num1 << "/" << num2 << "=" << Endl;
}
Else
cout << num1 << "/" << num2 << "=" << Endl;
}
}

if (k = = 0)//-------------------True fractional operation
{
int A, B, C, D;
A = rand ()% 100;
B = rand ()% 100;
C = rand ()% 100;
D = rand ()% 100;
for (;;)
{
if (> B&&b!=0 && (c>d&&d!=0))
{
Num1 = b/a;
num2 = d/c;
break;
}
Else
A = rand ()%;
b = rand ()% 100;
C = rand ()% 100;
D = rand ()%;

}
if (sym = = 0)
{
cout <<b<< "/" <<a<< "+" << d<< "/" <<c << "=" << Endl;
}
if (sym = = 1)
{
cout << B << "/" << a << "-" << D << "/" << c << "=" << Endl;
}
if (sym = = 2)
{
cout << B << "/" << a << "*" << D << "/" << c << "=" << Endl;
}
if (sym = = 3)
{
if (d = = 0)
{
num2 = (d+1)/(c+1);
cout << B << "/" << a << "/" << D << "/" << c << "=" << Endl;
}
Else
cout << B << "/" << a << "/" << D << "/" << c << "=" << Endl;
}
}
}
return 0;
}

Randomly generates 30 to integer true fraction arithmetic

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.