您的位置:首页 > 编程语言 > C语言/C++

<C++程序设计教程 钱能 著>例题 chapter1_9_2

2013-07-18 21:14 453 查看
/*****************************************************************

Function: display a odd number pattern as bellow:

*

***

*****

***

*

Author: beijiwei@qq.com

Date: 2013.7.18

******************************************************************/

#include<iostream>

using namespace std;

int main()

{

int i=0,j=0,n=0;

cout<<"Please input a number n: \n";

cin>>n;

for(i=0;i<n;i++)

{

if(i<(n+1)/2)

{

for(j=0;j<n/2-i;j++)

cout<<" ";

for(j=0;j<i*2+1;j++)

cout<<"*";

cout<<endl;

}

else

{

for(j=0;j<i-n/2;j++)

cout<<" ";

for(j=0;j<2*(n-i)-1;j++)

cout<<"*";

cout<<endl;

}

}



system("pause");

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: