打印输出九九乘法表

用do while 的解法:

 1 #include<iostream>
 2 using namespace std;
 3 void main()
 4 {
 5     int i=1,j;
 6     do
 7     {    j=1;
 8         while(j<=i)
 9         {
10             cout<<i<<'x'<<j<<'='<<i*j<<' ';
11             j++;
12         }
13         cout<<endl;
14         i++;
15     }
16     while(i<=9);
17 }

用for循环实现:

 1 #include<iostream>
 2 using namespace std;
 3 void main()
 4 {
 5     int i,j;
 6     for(i=1;i<=9;i++)
 7     {
 8         for(j=1;j<=i;j++)
 9             cout<<i<<"x"<<j<<"="<<i*j<<' ';
10             cout<<endl;
11     }
12 }

运行结果:

本文为博主原创文章,未经博主允许不得转载。
原文地址:https://www.cnblogs.com/iamvirus/p/2444961.html