Posted on 2011-09-25 16:13
hoshelly 閱讀(434)
評論(0) 編輯 收藏 引用 所屬分類:
C++
下午照樣看C++how to program,加油,要到數組和指針了,接下來就是類的深入剖析了,這幾天在加強火力猛攻這塊地方,哈哈,還是編程菜鳥!不過我自己感覺比大一那時候真的有點進步了,有那種coding 的感覺了,努力學習還是有收獲的。閑話休說,把今天下午自己寫的代碼發上來!
#include<iostream>
using namespace std;
int main()
{
int row,line;//定義行、列數的變量
for(row=1;row<=10;row++)
{
for(line=1;line<=row;line++)
cout<<"*";
cout<<endl;
}
cout<<"\n";//第一個圖形至此打印出來
for(row=10;row>=1;row--)
{
for(line=1;line<=row;line++)
cout<<"*";
cout<<endl;
}
cout<<"\n";//第二個圖形打印出來
for(row=10;row>=1;row--)
{
for(line=1;line<=row;line++)
cout<<"*";
cout<<endl;
for(line=1;line<=(11-row);line++)
cout<<" ";
}
cout<<"\n";// 第三個圖形打印出來
for(row=1;row<=10;row++)
{
for(line=1;line<=10-row;line++)
cout<<" ";
for(line=1;line<=row;line++)
cout<<"*";
cout<<endl;
} //最后一個圖形!
cout<<endl;
return 0;
}
程序運行結果
:

