rite a function, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example: the value of reverseDigit(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.

Respuesta :

following are the code in c language

#include<stdio.h> // header file  

int reverseDigit(int n);  // prototype of  reverseDigit function

int main()  // main method

{

int n;  // variable declaration

printf("Enter a number to reverse\n");

scanf("%d", &n);  // input value by user

int t=reverseDigit(n);  // calling  reverseDigit function

printf("the value of reverseDigit(%d)",n);  

printf(" is %d",t); // display reverse digit

 return 0;

}

int reverseDigit(int n)   // function definition of reverseDigit function

{

   int r=0;

    while(n!=0)  // iterating over the loop

  {

     r = r* 10;

     r= r+ n%10;

     n= n/10;

  }

  return(r);  // return the reverse digit

  }

Explanation:

In this we call a function  reverseDigit, from the main function after calling control moves to the definition of  reverseDigit, function ,the while loop is iterating .In the while loop, we find the remainder r when number is divided  by 10 then it will multiplied by 10 and add previous remainder after that number will be updated as n/10 . Then function will return number r and print them in main function.

output

Enter a number to reverse

12345

the value of reverseDigit(12345) is 54321