Chapter 6:
Looping Structures
Programming Exercise
Problem # 38:
Write a program to display the following output using loop:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
for(int i=5;i>=1;i--)
{
for(int k=1;k<=i;k++)
{
cout<<k<<"\t";
}
cout<<"\n";
}
getch();
}
#include<conio.h>
using namespace std;
int main()
{
for(int i=5;i>=1;i--)
{
for(int k=1;k<=i;k++)
{
cout<<k<<"\t";
}
cout<<"\n";
}
getch();
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
37. Program to display the following output using loop.
Comments
Post a Comment