SWAP FIRST AND LAST DIGIT
Problem Description
John has a task to swap the first and last digit of the given number. Help him to write a C program to input any number from user and swap the first and last digit of the number
CODING ARENA
#include <stdio.h>
#include <math.h>
int main()
{
int num,first,count,last,a,b,snum;
scanf("%d",&num);
count=log10(num);
first=num/pow(10,count);
last=num%10;
a=first*(pow(10,count));
b=num%a;
num=b/10;
snum=last*(pow(10,count))+(num*10+first);
printf("%d",snum);
return 0;
}
Test Case 1
Input (stdin)12345
Expected Output
52341
Test Case 2
Input (stdin)82341
Expected Output
12348
No comments:
Post a Comment