C++编程:用for或while循环编程输出以下图形

来源:百度知道 编辑:UC知道 时间:2024/05/01 06:12:56
是C++,不是C。就是输入用cin,输出用cout的。
第一幅:
*
**
***
****
*****
*****
*
第二幅:
*****
*
*****
****
***
**
*
一楼的朋友,我要用for或者while来编写呀

第一幅:
#include <iostream>
using namespace std;

int main()
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
cout<<"*****"<<endl;
cout<<"*"<<endl;

}
第二幅:
#include <iostream>
using namespace std;

int main()
{
cout<<"*****"<<endl;
cout<<"*"<<endl;
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j--)
cout<<"*";
cout<<endl;
}

}

你这个图又没有一定的规律,用for while岂不是多此一举。
第一幅:
#include<iostream>
using namespace std;
int main()
{
cout<<'*'<<endl;
cout<<"**"<<endl;
cout<<"***"<<endl;
cout<<"****"<<endl;