基本思路:
写一个output函数进行 * 的输出。
在主函数中调用output函数进行输出多少行每行输出多少个的操作。
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void output(int n){
for (int i = 1; i <= n; i++){
printf("*");
}
}
int main(){
int i, n;
for (i = 1; i < 8; i++){
n = 2 * i - 1;
output(n);
printf("\n");
}
for (i = 6; i > 0; i--){
n = 2 * i - 1;
output(n);
printf("\n");
}
system("pause");
return 0;
}