Chapter 6:
Looping Structures
Programming Exercise
Problem # 49:
Write a program to display the following output using loop:
1234567654321
123456 654321
12345 54321
1234 4321
123 321
12 21
1 1
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i, j, k, l, m, n;
for(i=7, n=7;i>=1;i--,n--)
{
for(j=1;j<=i;j++)
{
if(j==7)
break;
cout<<j;
}
for(m=i;m<=12-i;m++)
{
cout<<" ";
}
for(l=n;l>=1;l--)
{
cout<<l;
}
cout<<endl;
}
}
#include<conio.h>
using namespace std;
int main()
{
int i, j, k, l, m, n;
for(i=7, n=7;i>=1;i--,n--)
{
for(j=1;j<=i;j++)
{
if(j==7)
break;
cout<<j;
}
for(m=i;m<=12-i;m++)
{
cout<<" ";
}
for(l=n;l>=1;l--)
{
cout<<l;
}
cout<<endl;
}
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
48. Program to display the following output using while loop.
Comments
Post a Comment