☞ Write a program to print following pattern (March,2019)
Sample Input
253
Sample Output
2
2 5
2 5 3
5
5 3
3
Source Code
#include<stdio.h>
int main(){
int n,nrev=0,temp,i,j,c=0,temp2;
scanf("%d",&n);
temp=n;
while(temp!=0){
nrev=nrev*10+temp%10;
temp/=10;
c++;
}
while(nrev!=0){
temp=nrev;
for(i=1;i<=c;i++){
temp2=temp;
for(j=1;j<=i;j++,temp2/=10){
printf("%d%c",temp2%10,32);
}
printf("\n");
}
printf("\n");
nrev/=10;
c--;
}
}
Test Code
Sample Input
253
Sample Output
2
2 5
2 5 3
5
5 3
3
Source Code
#include<stdio.h>
int main(){
int n,nrev=0,temp,i,j,c=0,temp2;
scanf("%d",&n);
temp=n;
while(temp!=0){
nrev=nrev*10+temp%10;
temp/=10;
c++;
}
while(nrev!=0){
temp=nrev;
for(i=1;i<=c;i++){
temp2=temp;
for(j=1;j<=i;j++,temp2/=10){
printf("%d%c",temp2%10,32);
}
printf("\n");
}
printf("\n");
nrev/=10;
c--;
}
}
Test Code