Wednesday, October 4, 2017

Reverse Number

The program must accept a number N using command line and prints the reverse of the number N.

Example Input/Output 1:
Input:
12345
Output:
54321

Example Input/Output 2:
Input:
10900
Output:
901

Solution:
#include <stdio.h>
#include <stdlib.h>
void main(int c,int *s[])
{
    int r=0,n=atoi(s[1]);
    while(n)
    {
        r=r*10+n%10;
        n/=10;
    }
    printf("%d",r);
}
Share: