Multiplication table operations analysis

Multiplication table table, then I believe you are familiar with how the multiplication table as neatly arranged as a textbook in the code out of it.
Here you can use a for loop or a recursive loop to be resolved.
First, first to analyze, multiplication table in three values need: a multiplier, multiplicand and the number of the multiplication result. But if such a direct ride out of it will be the result of a problem that duplicate values, such as: 2 1 = 2 and 1 2 = 2 this type is repeated, then we should write the code to avoid such problems. There are two ways to solve this problem:
1. The first case is X the Y, X to the Y value of 9, X increment;
first determines whether X is less than 10, less than 10 when the output of the first X
the Y value obtained result. Y then be incremented, a determination carried out after the increment Y, Y is determined after the increment is equal to 10, if Y is equal to 10, X is incremented value, and assigned to the X and Y input newline then reload cycle, out of the end of the cycle is determined.
Multiplication table of this result is
Here Insert Picture Description
the following code:
int Tables (int, int); // declare method Prototype;
void main () {
Tables (. 1,. 1); // call the method;
}
int Tables (X int, int y) // set the X and Y values
{
IF (X <10) {
int K = X * Y; K // set a reception result of the data value of X * Y.
cout << x << "*" << y << "=" << k << ends;

cout << ends; // here is to determine whether the result value K is less than ten, is less than 10 give a multi-space, so that when the two-digit value can appear more beautiful
}
Y ++; // value output Y and then everything will be y ++ increment for increment cycle.
if (y == 10) {// value determined from the above operation where if statement is equal to 10
X ++; // increment multiplication table to redefine columns by x.
y = x; // x is assigned to Y
COUT << endl; // output wrap
}
NUM (X, Y); // Get X and Y values recall their
}
the else
{
return X, Y; and when X // when Y is greater than 10, the process returns
}
}

2, the second case is X- the Y, when X = Y, X + 1, Y 1 from the beginning again.
First determines whether X is less than 10, when X is less than 10, the output X
the Y value obtained result. Then determines whether the Y value is equal to the value of X, when X = Y, the newline, increment X, Y values and then assigned to 1, and then the recursive loop. When Y is not equal to X, Y be incremented, then recursive loop. When X 10 is equal to or greater than 10, out of the end of the cycle.
Multiplication table of this result is
Here Insert Picture Description
the following code:
int NUM_1 (int, int); // declare method Prototype;
void main () {
NUM_1 (. 1,. 1); // call the method;
}
int NUM_1 (X int, int Y)
{
IF (X <10) {
int K = X * Y; K // set a reception result of the data value of X * Y.
cout << x << "*" << y << "=" << k << ends; // retrieval of X, Y, K with value, and outputs it out
IF (K <10) {
COUT < <ends;
}
iF (X == Y) {// when when Y = X, X increment, Y 1 is assigned.
++ X;
Y =. 1;
COUT << endl;
} the else
{// when Y is not equal to the time X, Y increment.
y ++;

NUM_1 (X, Y);
} return the else {X, Y;} // When X and Y are greater than 10, the process returns
}

Guess you like

Origin blog.csdn.net/qq_39686486/article/details/89609089