Saturday, 5 March 2022

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

  1
  121
 12321
1234321


#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=1; i<=no; i++)
    {
        for(j=no-1; j>=i; j--)
        {
            printf(" ");
        }
        for(j=1; j<=i; j++)
        {
            printf("%d",j);
        }
        for(j=i-1; j>=1; j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }
    getch();
}

/*      output:

enter number for pyramid: 4

   1
  121
 12321
1234321

*/

No comments:

Post a Comment

python programs

1. sum of two number