zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

    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("
    ");
    35             }            
    36         }    
    37     }    
    38     return 0;  
    39 }  
  • 相关阅读:
    c#委托与事件
    c#垃圾回收与资源管理
    c#接口、抽象类
    c#集合类、ArrayList、queue
    c#位运算
    c#索引器
    c#使用属性封装
    c#继承
    c#数组参数
    Lambda表达式
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4159523.html
Copyright © 2011-2022 走看看