How to make a program that display the reverse of the number entered.
For example, if user enters 12345, then program should return (54321).
See it's python alright n = int(input()) m = str(n) print (int(m[::-1]))
in some cases the use of str() function is not allowed. then we can need an algorithm that can handle the task with integer values. num = int(input()) #return 0 # return can only be used from within functions rev = 0 # a variable to store calculation results while num > 0: rem = num % 10 # this returns the right most digit which is the remainder of a modulo division **1 num = num // 10 # this cuts off the rith most digit **2 rev = rev * 10 + rem # update the output value print(rev) **1 and **2 can also be done in one step by using the python built-in function divmod()
Sâñtôsh num=int (input("Please Enter the number: ")) x = num return 0 while num>0: num=num // 10 rev-rev*10+rem is rev) print ("Reverse of a entered number, " x", "is = ",rev)
Python — File Handling
Question is write a c program to print prime numbers up to n and print the largest number in array.
Achievements on Sololearn
How to draw in the console?