C++ 打印乘法表程序

编写一个 C++ 程序来打印乘法表,并附带示例。下面程序打印 4 和 5 的乘法表,直到 10。我们使用了嵌套的 for 循环来打印,其中第一个 for 循环(for (int i = 4; i < 6; i++))从 4 迭代到 5,第二个(for (int j = 1; j <= 10; j++)) 从 1 迭代到 10。

#include<iostream>
using namespace std;

int main()
{	
	cout << "\nMultiplication Table for 4 and 5  are\n";
	for (int i = 4; i < 6; i++)
	{
		for (int j = 1; j <= 10; j++)
		{
			cout << i << " * " << j << " = " << i * j <<"\n";
		}
    cout <<"\n ==========\n";
	}		
 	return 0;
}
Program to print Multiplication Table

使用 While 循环打印乘法表

这个C++ 程序允许用户输入小于 10 的任何值。然后,它将打印该数字到 10 的乘法表。

#include<iostream>
using namespace std;

int main()
{	
	int i, j;
	
	cout << "\nPlease enter the Positive Integer Less than 10 = ";
	cin >> i;
	
	cout << "\nMultiplication Table from " << i << " to " << " 10 are\n";
	while (i <= 10)
	{
		for (j = 1; j <= 10; j++)
		{
			cout << i << " * " << j << " = " << i * j <<"\n";
		}
    cout <<"\n ==========\n";
    i++;
	}		
 	return 0;
}
Please enter the Positive Integer Less than 10 = 9

Multiplication Table from 9 to  10 are
9 * 1 = 9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
9 * 10 = 90

 ==========
10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50
10 * 6 = 60
10 * 7 = 70
10 * 8 = 80
10 * 9 = 90
10 * 10 = 100

 ==========