REVERSE OF DIGITS
Problem Description
Mahesh played game with his friend sanjay to find Reverse of digits of the number he said.
Help to Mahesh and sanjay to solve it by your code using union.
Input Method
Integer ranges from 1 to 999
Output Method
Reverse of digits of the number
Mandatory:
1. Create union as "reverse"
2. The union variable name for "reverse" is "R"
CODING ARENA
#include <stdio.h>
union reverse
{
int n;
}R;
int main()
{
int remainder,s=0;
scanf("%d",&R.n);
while(R.n>0)
{
remainder=R.n%10;
s=s*10+remainder;
R.n=R.n/10;
}
printf("%d",s);
return 0;
}
Test Case 1
Input (stdin)134
Expected Output
431
Test Case 2
Input (stdin)1345
Expected Output
5431
No comments:
Post a Comment