C++大家帮忙

来源:百度知道 编辑:UC知道 时间:2024/09/21 00:37:00
1
12
123
1234
12345
123456
1234567
12345678
123456789

#include<stdio.h>
void main(){
int i,j;
for(i=0;i<9;i++){
for(j=9;j>i;j--)
printf(" ");
for(j=1;j<=i+1;j++)
printf("%d ",j);
putchar('\n');
}
}

#include<stdio.h>
#include<string.h>
int main()
{
int i, n = 9;
char buf[100] = {0};
for (i = 1; i <= n; i++){
sprintf(buf + strlen(buf), "%d", i);
printf("%*s\n", n, buf);
}
return 0;
}