Computer Science, asked by Jaehyuntoes, 1 month ago

WAP to print the sum of a number with its unit digit. Then display the unit digit
of the sum

Answers

Answered by Equestriadash
5

The following co‎des have been written using Python.

\tt b\ =\ int(in put("Enter\ a\ number:\ "))\\u\ =\ int(in put("Enter\ the\ unit\ digit:\ "))\\s\ =\ 0\\for\ i\ in\ range(1,\ b\ +\ 1):\\{\ \ \ \ \ } if\ str(i)[-1]\ ==\ str(u):\\{\ \ \ \ \ } s\ =\ s\ +\ i\\print(str(s)[-1],\ "is\ the\ unit\ digit\ of\ the\ sum\ obtained.")

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.

Answered by HarishAS
3

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 : )

Similar questions