View Code of Problem 54

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
	long int n;
	int i = 0,count = 1;
	int a[1000];
	scanf("%ld",&n);
	if(n>0&&n<10)
	{
		printf("%ld",n);
		exit(-1);
	}
	int temp = n;
	while(temp>=10)
	{
		++count ;
		temp/=10;
	}
	
	while(n>0)
	{
	    a[i] = n%10;
	    ++i;
	    n = n/10;
	}
	for(i=count-1;i>=0;--i)
	{
		if(i==0)
		  printf("%d",a[i]);
		else
		  printf("%d ",a[i]);
	}
	return 0;	

}

Double click to view unformatted code.


Back to problem 54