1. Using the looping statement. Create a program that will display the following:
A. *
***
****
****
***
*
B. @@@@@@@
@
@
@
@@@@@@@
//Solution [a]
using namespace std;
int main()
{
int i,L,j;
L=5;
for(i=1;i<=L;i=i+2)
{
for(j=1;j<=i;j++) cout<<"*"; cout<<endl;
}
for(i=L;i>=1;i=i-2)
{
for(j=1;j<=i;j++) cout<<"*"; cout<<endl;
}
}
//Solution [b]
using namespace std;
int main()
{
int j,L=5;
for(j=1;j<=L;j++) cout<<"@";
cout<<endl;
for(j=1;j<=3;j++) cout<<"@"<<endl;
for(j=1;j<=L;j++) cout<<"@";
}
Comments
Leave a comment