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 / abhi
#include<iostream.h>
using namespace std;
int main()
{
int n,i=1,j;
cout<<"Enter no of rows:";
cin>>n;
for(;i<=n;i++)
{
for(int k=1;k<i-1;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 ? | 9 Yes | 13 No |
Post New Answer View All Answers
What are properties in oop?
How is polymorphism achieved?
What is abstract class in oops?
Why is polymorphism needed?
What is oops concept with example?
What is the use of oops?
What is difference between oop and pop?
What is coupling in oops?
What is methods in oop?
What are the types of abstraction?
What type of loop is a for loop?
Why do we use oops?
What is the example of polymorphism?
What is the benefit of oop?
What is constructor in oop?