Swap digits of a number
Submit solution
C
Points:
20 (partial)
Time limit:
8.0s
Memory limit:
64M
Author:
Problem type
Allowed languages
Write a C program that accepts a number as input, swaps the first and last digit of the number and prints it.
Sample inputs
123
67834
Sample outputs
321
47836
Comments
include<stdio.h>
include<math.h>
int main() { int a,d,n,di,newnum; int p; scanf("%d",&n); p=(int)log10(n); d=n%10; di=pow(10,p); a=n/di; newnum=d*di+n%(di)+a-d; printf("\n%d",newnum); }