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~

  • 相关阅读:
    php+apache+mysql环境搭建
    怎么理解依赖注入
    maven修改远程和本地仓库地址
    idea创建的java web项目打包发布到tomcat
    MYSQL 导入导出数据库文件
    MySQL约束
    mysql字符集校对
    prime
    POJ-2564 01背包问题
    POJ-1564 dfs
  • 原文地址:https://www.cnblogs.com/zaric/p/zaric.html
Copyright © 2011-2022 走看看