zoukankan      html  css  js  c++  java
  • C little program exercise 01

         *
        ***
       *****
      *******
     *********
    ***********
     *********
      *******
       *****
        ***
         *

    output like this~when use diamond(7,'*');

    code:

    int diamond(int i,char x)
    {
        if(i%2 == 0)
        {
            printf("error");
            return 0;
        }
        for(int t=1; t<=(i-1)/2+1; t++)
        {      
            int blank = (i-2*(t-1))/2;
            while(blank > 0)
            {
                printf(" ");
                blank--;
            }
            int p=2*(t-1);
            while(p>=0)
            {
                printf("%c",x);
                p--;
            }
           
            printf("\n");
        }
        for(int t=(i-1)/2;t>0;t--)
        {
            int blank = (i-2*(t-1))/2;
            while(blank > 0)
            {
                printf(" ");
                blank--;
            }
            int p=2*(t-1);
            while(p>=0)
            {
                printf("%c",x);
                p--;
            }
            printf("\n");
        }
            return 1;
    }

    ok done~

  • 相关阅读:
    ACE_TASK学习
    tomcat:8005端口启动失败的解决办法
    centos7下安装jdk8
    解决github下载慢的一种方法
    page
    数据库
    做jar
    mvc:annotation-driven
    web.xml
    jsp九大内置对象el11内置对象
  • 原文地址:https://www.cnblogs.com/zaric/p/zaric.html
Copyright © 2011-2022 走看看