1.请尝试用for循环打印下面的图形。
#include <stdio.h>
#include <stdlib.h>
int main()
{int a,b,c,d,e;for(a = 1;a < 10;a++){if(a < 5){b = a * 2 - 1;c = 5 - a;}else{b = 9 - (a - 5) * 2;c = a - 5;}for(d = 0;d < c;d ++){printf(" ");}for(e = 0;e < b;e ++){printf("*");} printf("\n");}system("pause");return 0;
}
运行效果:
2.请尝试用for循环来打印一个九九乘法表。
#include <stdio.h>
#include <stdlib.h>
int main()
{int a,b;for (a=1;a<10;a++){for (b=1;b<=a;b++){printf("%d*%d=%2d ",b,a,a*b);}printf("\n");}return 0;
}
运行效果: