Write a C program to display the digits of a number as pyramid

(i)    Given an integer number, write a program that displays the number as follows :

First Line       : all digits
Second Line   : all excepts first digits
Third Line      : all excepts first two digits
………..
Last Line        : the last digit.
For example, the number 5678 will be displayed as :

5         6          7          8
6         7          8
7         8
8

Solution: 
#include<stdio.h>
int main(){
int x,arr[16],i=0,j;
printf("Enter the integer value: ");
scanf("%d",&x);
while(x > 0){
arr[i]= x % 10;
x = x / 10;
i++;
}
for(j=i-1; j >= 0; j--){
for(i=j; i>=0;i--){
printf("%d ",arr[i]);
}
printf("\n");
}
return 0;
}

Posted in CSE

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>