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


Please Help Members By Posting Answers For Below Questions

What is polymorphism explain?

695


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

635


What is difference between inheritance and polymorphism?

575


How do you explain polymorphism?

596


What is new keyword in oops?

593






What is oops in simple words?

585


Why is destructor used?

587


what's the basic's in dot net

1742


What is pointer in oop?

541


What is balance factor?

589


What is object in oop with example?

706


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1395


Is html an oop?

584


Where You Can Use Interface in your Project

1429


What does it mean when someone says I oop?

587