int reversed_number(int number){
int reversed = number;
//TODO: if input is 12345, return 54321
return reversed;
}
I need a C code that reverses the input please.
//C program
#include<stdio.h>
//function to reverse the number
int reversed_number(int number)
{
//variable declaration
int reversed = number;
int rev=0,remainder;
//while loop to reverse the number
while(reversed!=0)
{
remainder =reversed%10;
rev = rev*10 + remainder;
reversed = reversed / 10;
}
reversed = rev;
return reversed;//return reversed number
}
int main()
{
int number;
//user input for number to be reversed
printf("Enter a number:");
scanf("%d",&number);
//returned reversed number stored in reversed
int reversed = reversed_number(number);
printf("Reversed number is:%d ",reversed);//print the reversed number
}
Output::
Get Answers For Free
Most questions answered within 1 hours.