Given a number, write a c program using while loop to reverse the digits of the number.
Answers
Answered by
2
Answer:
#include<stdio.h>
int main(){
int rev=0,rem,n;
scanf("%d",&n);
while(n!=0){
rev=rev*10+n%10;
n/=10;
}
printf("reverse:%d",rev);
Explanation:
n=1234 //input
while(n!=0){ // runs the loop until n is !=0
rev=rev*10+n%10; //returns last digit i.e 4
n/=10; // returns all digits except last digit i.e 123
}
Similar questions
Geography,
6 months ago
Social Sciences,
6 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Physics,
1 year ago