What will be the code for>?

Write a program that prompts the user to enter an integer from 1 to 15 and displays
a pyramid . For example if the input integer is 6 ,the output is shown below :


1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6

Showing Answers 1 - 1 of 1 Answers

vinoth kumar

  • Sep 10th, 2012
 

Code
  1. int main()

  2. {

  3.         int n,m,i,j;

  4.         scanf("%d",&n);

  5.         for(i=1;i<=n;i++)

  6.           { for(j=1;j<=n-i;j++)

  7.                printf(" ");

  8.           for(j=i;j>=1;j--)

  9.               printf("%d        ",j);

  10.            for(j=2;j<=i;j++)

  11.               printf("%d        ",j);

  12.           printf("

  13. ");

  14.           }

  15.         return 0;

  16. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions