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


Please Help Members By Posting Answers For Below Questions

What is encapsulation in oop?

601


What is abstraction in oops with example?

770


c++ program to swap the objects of two different classes

1759


How do you use inheritance in unity?

586


What is difference between inheritance and polymorphism?

564






Why is oop better than procedural?

602


What is the importance of oop?

605


Who invented oop?

649


What are functions in oop?

582


Can private class be inherited?

615


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1145


Which is not an object oriented programming language?

537


What is the purpose of enum?

579


Is enum a class?

602


Why do we need oop?

661