WAP to print the sum of a number with its unit digit. Then display the unit digit
of the sum
Answers
The following codes have been written using Python.
The aim of the program is to traverse from 1 to all the numbers till 'b', and choose those numbers whose unit's place digit is 'u'. We do the traversing using a for loop, which is an iteration statement used for repeated checking. We check for the unit's place digit using a conditional statement. If the statement results to True, it will perform the succeeding command, which is to add it up. Once all the numbers have been traversed through, the final output of printing the unit's place digit of the obtained sum is performed.
Explanation:
Steps followed:
1) Getting a number as input from the user.
2)Finding the unit digit of the number
3)Calculating the sum of the number and its unit digit.
4)Finding the resultant number's unit digit.
Program:
x = int(input('Enter a number: ')) #Number as input from the user
y = x%10 #Unit digit of the number
z = x+y #Sum of number and its unit digit
print('The sum of the number and its unit digit is : ' , z)
print('Unit digit of the sum is : ' , z%10)
This is a very simple approach for this question. And hope this helps : )