Reversed Sum - c - Spicy Coders

Recent

Monday, July 10, 2017

Reversed Sum - c

The number N is passed as input. The program must print the difference between the number N and its reverse R.

Input Format:

The first line denotes the value of N.

Output Format:

The first line contains the value of N-R

Boundary conditions:10<=n<=999999

Example Input/Output 2:

Input:
42

Output:
18

Explanation:The output is 42-24 = 18

Example Input/Output 2:

Input:
555

Output:
0

Explanation:The output is 555-555 = 0

Example Input/Output 3:

Input:
125

Output:
-396

Explanation: The output is 125-521 = -396

Coding:

#include <stdio.h>
int main()
{
int n,m,r=0;
scanf("%d",&n);
 m = n;
 while(m)
 {
    r = r*10+m%10;
    m = m/10;
 }
printf("%d",n-r);
}

}


No comments:

Post a Comment