c语言题,求大佬解答
2020-03-24
算法1:
#include <stdio.h>
void printTriangle(int);
int main() {
int n;
scanf("%d", &n);
printTriangle(n);
return 0;
}
void printTriangle(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i - 1; j++)
putchar(' ');
for (int k = 1; k <= n - i + 1; k++)
putchar('*');
putchar('\n');
}
}
算法2:
#include <stdio.h>
void printTriangle(int);
int main() {
int n;
scanf("%d", &n);
printTriangle(n);
return 0;
}
void printTriangle(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
if (i > j)
putchar(' ');
else
putchar('*');
putchar('\n');
}
}