I need to write a simple function in C for homework, and this is my question.... Write a function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367. If anyone can help me i would greatly appreciate it, thanks!
#include <stdio.h> int reverse(int digit); int main() { printf("%d",reverse(7643)); return 0; } int reverse(int digit) { int reversedigit = 0; while(digit) { reversedigit += digit%10; reversedigit*= 10;//10 digit /=10; } reversedigit /= 10 return reversedigit; }