For循环嵌套输出类似QQ好友列表
代码示例:#include <stdio.h>
int main () {
int temp_i = 0;
int temp_j = 0;
while (temp_i <= 0) {
printf("请输入好友列表数:");
scanf("%d", &temp_i);
while (temp_j <= 0) {
printf("请输入好友数:");
scanf("%d", &temp_j);
}
}
// printf("temp_i=%d,temp_j=%d\n", temp_i, temp_j);
for (int i = 0; i < temp_i; i++) {
printf("好友列表%d\n", i+1);
for (int j = 0; j < temp_j; j++) {
printf(" 好友%d\n",j+1);
}
}
return 0;
}运行结果:请输入好友列表数:3
请输入好友数:5
好友列表1
好友1
好友2
好友3
好友4
好友5
好友列表2
好友1
好友2
好友3
好友4
好友5
好友列表3
好友1
好友2
好友3
好友4
好友5
同样的原理可以输出九九乘法表:
#include <stdio.h>
int main() {
for (int i = 1; i < 10; i++) {
for (int j = 1; j <= i; j++) {
printf("%d×%d=%d",i, j, i*j);
}
printf("\n");
}
return 0;
}输出结果:1×1=1
2×1=22×2=4
3×1=33×2=63×3=9
4×1=44×2=84×3=124×4=16
5×1=55×2=105×3=155×4=205×5=25
6×1=66×2=126×3=186×4=246×5=306×6=36
7×1=77×2=147×3=217×4=287×5=357×6=427×7=49
8×1=88×2=168×3=248×4=328×5=408×6=488×7=568×8=64
9×1=99×2=189×3=279×4=369×5=459×6=549×7=639×8=729×9=81
页:
[1]