please help i cant seem to figure is question out. Write a C program to reverse
ID: 3639443 • Letter: P
Question
please help i cant seem to figure is question out.Write a C program to reverse the digits of a positive integer number. For example, if the number is 8735 the result displayed should be 5378. (Hint: Use a do statement and continuously strip off and display the units digit of the number. If the variable num initially contains the number entered, the units digit is obtained as (num % 10). After a units digit is displayed, dividing the number by 10 sets up the number for the next iteration. Thus 8735 % 10 is 5 and 8735/10 is 873. The do statement should continue as long as the remaining number is not zero)
Explanation / Answer
#include int reversDigits(int num) { int rev_num = 0; while(num > 0) { rev_num = rev_num*10 + num%10; num = num/10; } return rev_num; } int main() { int num = 4562; printf("Reverse of no. is %d", reversDigits(num)); getchar(); return 0; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.