0

How to print user input in last line of this program ? Thank for help 😊

https://code.sololearn.com/cizGsJnC55j7/?ref=app

6th Mar 2022, 5:35 AM
Abhay mishra
Abhay mishra - avatar
2 Answers
+ 4
Abhay mishra Assign n to a temp variable then print that temp variable in the last line. Or instead of using original variable in while loop you can use temp variable. int temp = n; Now use this temp in while loop while (temp != 0) { }
6th Mar 2022, 6:36 AM
A͢J
A͢J - avatar
+ 1
Your code is OK but the input value n become 0 (n=0).Reason , this variable was changed by calculating in while loop until 0. To show user input value , add one more int variable : (int num) and assign n value to it. That means your code after modify: int n , remainder , reverse = 0 ; int num; // Add new variable printf("enter your value = ") ; scanf("%d" , &n) ; num = n; // assign n value while(n != 0){ remainder = n % 10 ; reverse = reverse * 10 + remainder ; n = n / 10 ; } //printf("\n The mirror value of %d is %d" , n , reverse) ; // replace n by num printf("\n The mirror value of %d is %d" , num, reverse) ; return 0 ; hop to help you
6th Mar 2022, 9:11 AM
Ueda