编写程序输出一下的图形:
12 3
4 5 6
7 8 9 10
root@~ #cat tri.c #include <stdio.h> int main (void) { int a,b,c=1,i,j; void space (int n); printf ("Enter number of line:"); scanf ("%i",&i); j=i+1; for(a=0;a<j;a++,i--){ space(i); for(b=0;b<a;b++,c++) { printf ("%i\t\t",c); } printf ("\n"); } return 0; } void space (int n) { int i; for(i=0;i<n;i++) { printf ("\t"); } }
root@~ #./tri Enter number of line:3 1 2 3 4 5 6 root@~ #./tri Enter number of line:4 1 2 3 4 5 6 7 8 9 10 root@~ #./tri Enter number of line:5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 root@~ #
root@~ #cat tri.c #include <stdio.h> int main (void) { int a,b,c=1,i,j,k; printf ("Enter number of line:"); scanf ("%i",&i); j=i+1; for(a=0;a<j;a++,i--){ for(k=0;k<i;k++) { printf ("\t"); } for(b=0;b<a;b++,c++) { printf ("%i\t\t",c); } printf ("\n"); } return 0; } root@~ #