Write a program to accept a number and to print numbers in
pyramid format?
for eg:for a no. 5
1
212
32123
4321234
543212345
Answer Posted / shravya
#include<iostream.h>
using namespace std;
int main()
{
int n,i,j;
cout<<"Enter no of rows:";
cin>>n;
for(i=1;i<=n;i++)
{
for(int k=1;k<=n-i;k++)
cout<<" ";//for spaces from right
for(j=i;j>0;j--)
cout<<j;//prints rightside nums
for(int l=2;l<=i;l++)
cout<<l;//prints leftside nums
cout<<endl;
}
return 0;
}
Is This Answer Correct ? | 23 Yes | 15 No |
Post New Answer View All Answers
What is encapsulation in oop?
What is abstraction in oops with example?
c++ program to swap the objects of two different classes
How do you use inheritance in unity?
What is difference between inheritance and polymorphism?
Why is oop better than procedural?
What is the importance of oop?
Who invented oop?
What are functions in oop?
Can private class be inherited?
Give an example where we have to specifically use C programming language and C++ programming language cannot be used?
Which is not an object oriented programming language?
What is the purpose of enum?
Is enum a class?
Why do we need oop?