11 Ocak 2013 Cuma

星號菱形輸出


問題描述:

試寫一個程式,可以繪製出如下的圖形:(若輸入偶數,將自動少一行 ) 。
...*...
..***..
.*****.
*******
.*****.
..***..
...*...
輸入說明輸入一個正整數。
輸出說明:請參考範例輸出。範例:

Sample Input:Sample Output:
7...*...
..***..
.*****.
*******
.*****.
..***..
...*...
  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. int main()  
  5. {  
  6.  int i,j,k,n;  
  7.  scanf("%d",&n);  
  8.   
  9.  for(i=1; i<=(n+1)/2; )  
  10.     {  
  11.         for(k=2; (n+1)/2-i+1>=k; k++)  
  12.         printf(".");  
  13.         for(j=1; j<2*i; j++)  
  14.         printf("*");  
  15.         for(k=2; (n+1)/2-i+1>=k; k++)  
  16.         printf(".");  
  17.         printf("\n");  
  18.         i++;  
  19.     }  
  20. if(2*i-1>=n)  
  21.     {  
  22.         for(i=(n+1)/2-1; i>=1; i--)  
  23.         {  
  24.         for(k=2; (n+1)/2-i+1>=k; k++)  
  25.         printf(".");  
  26.         for(j=1; j<2*i; j++)  
  27.         printf("*");  
  28.         for(k=2; (n+1)/2-i+1>=k; k++)  
  29.         printf(".");  
  30.         printf("\n");  
  31.         }  
  32.     }  
  33. system("pause");  
  34. return(0);  
  35. }  

Hiç yorum yok:

Yorum Gönder

Binary Conversion

Problem Description Convert two binary numbers into two decimal numbers and compute their sum. Your program has to convert two binary number...