zoukankan      html  css  js  c++  java
  • “*”菱形打印程序

    闲来无事,还记得以前课本上的那个课后习题,那就编个小程序玩玩。

     1 //date:2013/8/14
     2 //designer :pengxiaoen
     3 //function: just for fun
     4 
     5 #include "stdio.h"
     6 #include "math.h"
     7 int main ()
     8 {
     9   int i,j,k,r;
    10   int t,temp1,temp2;
    11 //-------------------------------------------------------------  
    12   printf ("please enter a odd number between  3  and 30 : ");
    13   scanf("%d",&r);
    14   while ((r<3) || (r>30) || ((r+1)%2)  )
    15   {
    16      printf("
     error 
    
    ");
    17      printf ("please enter a odd number between  3  and 30 : ");
    18      scanf("%d",&r);
    19   }
    20 
    21   t = (r-1)/2;
    22    temp1 = t+1;
    23 //--------------------------------------------------------------  
    24   for(i=0; i<r;i++)
    25   {    
    26      temp1--;
    27      for(j=0; j<=abs(temp1);j++)   printf(" ");                         
    28      
    29      if(i<=t) temp2 = 2*i+1;
    30      else temp2 = 2*(r-i)-1;
    31      for(k=0; k<temp2;k++)   printf("*");
    32      
    33      printf("
    "); 
    34      
    35   }
    36   system("pause");
    37 }


    执行结果

  • 相关阅读:
    seajs快速了解
    lazyload.js详解
    iScroll-js—“smooth scrolling for the web”
    Backbone学习笔记一Backbone中的MVC
    JMH基准测试框架
    idea 下运行安卓项目
    安卓
    C++
    看完
    四叉树的js实现
  • 原文地址:https://www.cnblogs.com/sepeng/p/3257732.html
Copyright © 2011-2022 走看看