Random Number Pyramid

Q. Write a C program to print the any entered number, digit pyramid,

For example:

if entered number is : 87954
then output must be as:

87954
7954
954
54
4

Ans.

/*c program for random digit pyramid*/
#include<stdio.h>
int main()
{
 int n[50],i,j=0,k,r,c,len;
 printf("Enter total length of number : ");
 scanf("%d", &len);
 printf("\nNote: Entered digit MUST be single.\n\n");
 for(i=0; i<len; i++)
 {


   printf("Enter %d single digit : ",i+1);
   scanf("%d", &n[i]);
 }
 printf("\n");
 for(r=1; r<=len; r++,j++)
 {
  for(c=r,k=j; c<=len; c++,k++)
     printf("%d",n[k]);
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:



Output of Random Number Pyramid C program
Figure: Screen shot for Random Number Pyramid C program


Comments