View Code
1 //打印菱形 2 #include<stdio.h> 3 #include<math.h> 4 int main() 5 { 6 int h,n,i,j; 7 while(scanf("%d",&h)!=-1) 8 { 9 n=(h+1)/2; 10 11 for(i=1;i<=h;i++) 12 { 13 for(j=1;j<=abs(n-i);j++) 14 printf(" "); 15 for(j=(h-abs(n-i));j>=abs(n-i)+1;j--) 16 printf("*"); 17 18 printf("\n"); 19 } 20 } 21 return 0; 22 } 23 /* 24 * 25 *** 26 ***** 27 ******* 28 ***** 29 *** 30 * 31 */ 32 33 打印数字菱形 34 #include<stdio.h> 35 #include<math.h> 36 int main() 37 { 38 int n,i,j,k,h; 39 while(scanf("%d",&n)!=-1) 40 { 41 h=2*n-1; 42 for(i=1;i<=h;i++) 43 { 44 for(j=1;j<=abs(n-i);j++) 45 printf(" "); 46 for(k=1;k<=n-abs(n-i);k++) 47 printf("%d",k); 48 for(k=k-2;k>=1;k--) 49 printf("%d",k); 50 printf("\n"); 51 } 52 } 53 return 0; 54 } 55 /* 5 56 1 57 121 58 12321 59 1234321 60 123454321 61 1234321 62 12321 63 121 64 1