Saturday, 5 March 2022

16. Write a program that accepts an integer N, if the integer N = 4,then print the pyramid :

4 4 4 4
 3 3 3
  2 2
   1


#include<stdio.h>
#include<conio.h>

void main()
{
    int i,j,no;
    clrscr();

    printf("enter number for pyramid: ");
    scanf("%d",&no);

    printf("\n");

    for(i=no; i>=1; i--)
    {
        for(j=i; j<=no-1; j++)
        {
            printf(" ");
        }
        for(j=1; j<=i; j++)
        {
            printf("%d ",i);
        }
        printf("\n");
    }
    getch();
}

/*      output:

enter number for pyramid: 4

4 4 4 4
 3 3 3
  2 2
   1

*/


 

No comments:

Post a Comment

python programs

1. sum of two number