#include < stdio.h >
int main() {
int num, rev = 0;
//Reading a number
printf("Please enter a number: ");
scanf("%d", & num);
//finding reverse number using while loop
while (num > 0) {
rev = rev * 10;
rev = rev + num % 10;
num = num / 10;
}
printf("Reversed number is = %d ", rev);
return 0;
}
Reverse a Number using for loop
#include < stdio.h >
int main() {
int num, rev;
//Reading a number
printf("Please enter a number: ");
scanf("%d", & num);
//finding reverse number using for loop
for (rev = 0; num > 0; num = num / 10) {
rev = rev * 10;
rev = rev + num % 10;
}
printf("Reversed number is = %d", rev);
return 0;
}
Reverse a Number using while loop
Reverse a Number using for loop
Result:
Please enter a number: 123
Reversed number is = 321
need an explanation for this answer? contact us directly to get an explanation for this answer