首页 > 编程语言 > 详细

武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

时间:2014-12-12 14:36:15      阅读:1028      评论:0      收藏:0      [点我收藏+]

Problem Description

输入n,输出对应的边长为n的空心正六边形。

为方便看图,样例中点 ‘.‘ 表示空格,打印图形时请打印空格而非小圆点。

Input

 边长n.(n<=20)

Output

 边长为n的正六边形

 

Sample Input

5

Sample Output

.....*****
....*.....*
...*.......*
..*.........*
.*...........*
..*.........*
...*.......*
....*.....*
.....*****
 1 #include<stdio.h>
 2 #include<math.h>
 3 void prt(char c, int count)  
 4 {  
 5     while(count--)  
 6     {  
 7         printf("%c",c);  
 8     }  
 9 }  
10 
11 int main()  
12 {  
13     int N, L;
14     while(scanf("%d",&N)!=EOF)
15     {
16         if(N>0 && N<=20)
17         {
18             L=0;
19             for(; L < 2 * N - 1; L++)  
20             {  
21                 prt( , 1); 
22                 prt( , abs(N - L-1)); 
23                 
24                 if(0 == L || L == 2 * N - 2)  
25                 {  
26                     prt(*, N);  
27                 }  
28                 else  
29                 {  
30                     prt(*, 1);
31                     prt( , 3 * N - 4 -(abs(L+1 - N) * 2));
32                     prt(*, 1);
33                 }  
34                 printf("\n");
35             }            
36         }    
37     }    
38     return 0;  
39 }  

 

武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

原文:http://www.cnblogs.com/liuwt365/p/4159523.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!