加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C++编程用*号打印菱形及其它图案

(2014-12-11 18:35:55)
标签:

it

分类: 菜鸟起飞

菜鸟刚刚起飞,就遇到输出菱形之类的问题,于是,这一系列的程序就被写出来了、

输出任意行菱形   代码:

#include
void main(){
 int i,j,n;
 cout<<"输入您想输出的菱形行数:";                        
  cin>>n;

 for(i=0;i<=(n/2);i++){
  for(j=0;j<=(n-1);j++){                                                     
   if(j<(n/2-i)||j>(n/2+i))
    cout<<' ';
   else cout<<'*';
  }cout<<endl;
 }
 for(i=0;i
  for(j=0;j<=n-1;j++){
   if(j<1+i||j>=n-1-i)
    cout<<' ';
   else cout<<'*';
  }cout<<endl;
 }
            http://s11/mw690/003d6ycpzy6OiNZLlmq7a&690

另一种形状  代码:

#include
void main(){
 int i,j;
 for(i=0;i<4;i++){
  for(j=0;j<7;j++){
   if(j<3-i||j>3+i)
    cout<<' '<<' ';
   else cout<<'*'<<' ';
  }cout<<endl;
 }
 for(i=0;i<3;i++){
  for(j=0;j<7;j++){
   if(j>=1+i&&j<=5-i)
    cout<<'*'<<' ';
   else cout<<' '<<' ';
  }cout<<endl;
 }
}

http://s11/mw690/003d6ycpzy6OiO6MpYe1a&690

还有the left of the heart and the whole hearts  就是打印出来,丑点儿、 代码如下:

#include
void main(){
 int i,j;
 for(i=0;i<=2;i++){
  for(j=0;j<=12;j++){
   if(j<2-i||(j>4+i&&j<8-i)||j>10+i)
    cout<<' ';
   else cout<<'*';
  }cout<<endl;
 }
 for(i=0;i<2;i++){
  for(j=0;j<13;j++){
   cout<<'*';
  }cout<<endl;
 }
 for(i=0;i<6;i++){
  for(j=0;j<13;j++){
   if(j<1+i||j>12-i)
    cout<<' ';
   else cout<<'*';
  }cout<<endl;
 }
}

http://s9/mw690/003d6ycpzy6OiOumrLq58&690

another:

#include
void main(){
 int i,j;
 for(i=0;i<=2;i++){
  for(j=0;j<=6;j++){
   if(j<2-i||j>4+i)
    cout<<' ';
   else cout<<'*';
  }cout<<endl;
 }
 for(i=0;i<2;i++){
  for(j=0;j<7;j++){
   cout<<'*';
  }cout<<endl;
 }
 for(i=0;i<6;i++){
  for(j=0;j<7;j++){
   if(j<1+i)
    cout<<' ';
   else cout<<'*';
  }cout<<endl;
 }
}

http://s7/mw690/003d6ycpzy6OiOw9sYm06&690



                                                 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有