1.

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

Answer»

#includeint 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 //inputwhile(n!=0){ // runs the loop until n is !=0rev=rev*10+n%10;  //RETURNS LAST digit i.e 4n/=10; // returns all DIGITS EXCEPT last digit i.e 123}



Discussion

No Comment Found