Chapter 6:
Looping Structures
Programming Exercise
Problem # 50:
Write a program to display the following output using loop:
&
& &
& &
& &
& &
& &
& &
& &
& &
&&&&&&&&&&&&&&&&&&&
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int count=9;
for(int i=9;i>=1;i--)
{
for(int j=18;j>=1;j--)
{
if(j==count||i==j)
cout<<"&";
else
cout<<" ";
}
cout<<endl;
count++;
}
for(int k=1;k<=19;k++)
cout<<"&";
getch();
}
#include<conio.h>
using namespace std;
int main()
{
int count=9;
for(int i=9;i>=1;i--)
{
for(int j=18;j>=1;j--)
{
if(j==count||i==j)
cout<<"&";
else
cout<<" ";
}
cout<<endl;
count++;
}
for(int k=1;k<=19;k++)
cout<<"&";
getch();
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
49. Program to display the following output using loop.
Comments
Post a Comment