## 7.08.2013

### 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:

 Figure: Screen shot for Random Number Pyramid C program

1. Haha. This was our lesson last week. Thank you for posting it :)

2. This solution is not upto the mark,,,we cant expect from user to input everything in advance...like length of number,,,each digit individually..
Check out this-
#include
#include
void main()
{
int num,temp,k=1,len=0;
printf("Enter any number : \n");
scanf("%d",&num);
temp=num;
while(temp>0)
{temp=temp/10;
len++;

}
for(int i=1;i<=len;i++)
{
k=k*10;
}
for(int i=1;i<=len;i++)
{
printf("%d\n",num%k);
k=k/10;
}
getch();

}

1. @HR GROUP,

Thanks for sharing above codes.