Computer Science, asked by Akaahdeep6704, 11 months ago

Given a number, write a c program using while loop to reverse the digits of the number.

Answers

Answered by jtv
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