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 oops with example?

566


What is abstraction example?

624


What is abstraction with example?

608


Which language is pure oop?

552


What are the three parts of a simple empty class?

1462






What causes polymorphism?

577


How many human genes are polymorphic?

577


What exactly is polymorphism?

612


What are the components of marker interface?

605


Write a program to sort the number with different sorts in one program ??

1922


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

1795


How Do you Code Composition and Aggregation in C++ ?

24205


What is encapsulation c#?

602


What do you mean by Encapsulation?

645


Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation

1664