一、for循环的嵌套
二、代码实践
代码参考
#include "iostream"
using namespace std;
int main()
{
// for循环嵌套的九九乘法表
for(int j = 1;j <= 9;j++) {
for( int i = 1;i <= j; i++) {
cout << i << "*" << j << "=" << i*j << "\t";
}
cout << endl;
}
return 0;
}
三、练习题
(1)for和while混合嵌套的九九乘法表
代码参考
#include "iostream"
using namespace std;
int main()
{
// for循环嵌套的九九乘法表
for(int j = 1;j <= 9;j++) {
int i = 1;
while(i <= j) {
cout << i << "*" << j << "=" << i*j << "\t";
i++;
}
cout << endl;
}
return 0;
}
(2)进阶for循环案例:猜数字
代码参考