Write a algorthim only by using while loop
That uses a function, reverseDigit. The function takes an integer as a parameter and returns the number with its digits reversed. For example, the value ofreverseDigit(12345) is 54321; the value of reverseDigit(5600) is 65; the value of reverseDigit(7008) is 8007; and the value of reverseDigit(-532) is -235.
/* program to reverse an integer number.*/
#include <stdio.h>
/* function: reverseNum
to reverse an integer number.
*/
int reverseNum(int num)
{
int sum=0,rem;
while(num > 0)
{
rem=num%10;
sum=(sum*10)+rem;
num=num/10;
}
return sum;
}
int main()
{
int n;
printf("\nEnter an integer number :");
scanf("%d",&n);
printf("\nReverse Number is : %d\n",reverseNum(n));
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.