Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! π πΉLearn advanced coding techniques in C& C++ πΉMaster Linux internals & shell scripting πΉDeep dive into Data Structures & Algorithms πΉExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) πΉGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C Program to Reverse a Number Using While Loop
✅ C Program to Reverse a Number Using While Loop
#include <stdio.h>
int main() {
int num, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
while(num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num = num / 10;
}
printf("Reversed number = %d", reversed);
return 0;
}
π Explanation:
This program reverses a given number using a while loop. It extracts digits one by one from the end and rebuilds the number in reverse order.
- Take user input using
scanf(). - Use
num % 10to extract the last digit. - Multiply reversed number by 10 and add the extracted digit.
- Remove last digit using
num = num / 10. - Repeat until the number becomes 0.
This program is commonly asked in beginner coding interviews and programming exams.
π§Ύ Sample Output:
Enter a number: 1234 Reversed number = 4321
π Keywords:
C program to reverse a number, reverse number in C using while loop, C programming examples, beginner C programs, number manipulation in C, C logic building program
π Hashtags:
#CProgramming #ReverseNumber #LearnC #CodingForBeginners #WhileLoop #1printf
π Search Description:
Learn how to reverse a number in C using while loop. Beginner-friendly program with step-by-step explanation and sample output.
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment