5️⃣C Program to Reverse a Number (With Program and Explanation)

 

๐Ÿ”น C Program to Reverse a Number

๐Ÿ“Œ Problem Statement

Write a C program to reverse a given integer number.


๐Ÿ’ป C Program Code

#include <stdio.h> int main() { int num, reverse = 0, remainder; printf("Enter a number: "); scanf("%d", &num); while (num != 0) { remainder = num % 10; reverse = reverse * 10 + remainder; num = num / 10; } printf("Reversed number = %d", reverse); return 0; }

๐Ÿง  Explanation

  • num stores the original number.

  • remainder stores the last digit of the number.

  • reverse stores the reversed number.

  • The while loop:

    • Extracts the last digit using % 10

    • Appends it to reverse

    • Removes the last digit using / 10

  • The loop continues until the number becomes 0.


๐Ÿงช Example Output

Enter a number: 1234 Reversed number = 4321

✅ Conclusion

This program efficiently reverses any integer number using basic arithmetic operations and loops in C.


๐Ÿ“˜ C Programming Series – What’s Next?

๐Ÿ‘‰ In the next post of this series, we will learn how to write a C Program to Find Factorial of a Number with complete explanation and output examples. Stay tuned! ๐Ÿš€

Comments

Popular posts from this blog

⓮C Program to calculate Simple Interest (With Program and Explanation)

⑫ C Program to Swap Two Numbers Without Using a Temporary Variable (With Program and Explanation)

9️⃣C Program to Find LCM of Two Numbers (With Program and Explanation)