Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / 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

Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / pravin pawar

public static void main(String args[])
{
for(int r=1;r<=5;r++)
{
for(int s=5-r;s>0;s--)

System.out.print(" ");

for(int c=r;c>=1;c--)
System.out.print(c);

for(int c=2;c<=r;c++)

System.out.print(c);

System.out.print("\n");
}
}

Is This Answer Correct ?    8 Yes 3 No

Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / fekedabekele

write program using java
1
212
32123
3421234
234512345

Is This Answer Correct ?    8 Yes 4 No

Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / rathod rajesh

for(int i=1;i<=5;i++)
{
for(int k=5;k>=i;k--)
{
System.out.print(" ");
}

for(int j=i;j>=1;j--)
{
System.out.print(j);
}
for(int j=2;j<=i;j++)
{
System.out.print(j);
}
System.out.println();

}

Is This Answer Correct ?    2 Yes 1 No

Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / suresh

#include <stdio.h>

int main() {
int i;
int j;
int k;

for (i = 1; i <= 5; i++) {
for (j = i; j >= 1; j--) {
printf("%d", j);
}
for (k = 2; k <= i; k++) {
printf("%d", k);
}

printf(" ");
}

printf("n");

return 0;
}

Is This Answer Correct ?    4 Yes 5 No

Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / akshaya

#include <iostream.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();
cout<<"
Enter the value of n:";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<" ";
}
}
}

Is This Answer Correct ?    2 Yes 4 No

Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 ..

Answer / 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

More OOPS Interview Questions

What are the four main oops concepts?

1 Answers  


What is encapsulation process?

0 Answers  


what about you? wahat is your object? introduce your self?

1 Answers   Ajmal Perfumes, TCS,


We have a scale and 7 balls. 1 ball is heavier than all the rest. How to determine the heaviest ball with only 3 possible weighing attempts?

8 Answers   IBM, Sage, Vertex,


Why polymorphism is used in oops?

0 Answers  


what is the difference between class and object?

9 Answers  


what is the difference between class and structure in C++?

9 Answers   Aspire, IBS, TCS,


What is the main difference between C++ and Java

11 Answers   TCS,


How to overload new operator in c++

2 Answers  


3. Differentiate verification and validation.

1 Answers  


i hav very low percentage in 12th n BSCwhich is around 50.......coz it was just imposed on me 2 b a science graduate,nw m doin MCA n hav aggregate 74% ....what shud i answer if company's HR ask me about dis much low previous percentage??????

3 Answers   Infosys,


There are 2 empty jars of 5 and 3 liters capacity. And a river is flowing besides. I want to measure 4 liters of wanter using these 2 jars. How do you do this?

4 Answers  


Categories