Problem 2 :
Q2 :
Sum of the digits of the given positive integer number N is UNO or not.
Problem Statement :
Given a positive integer number N, reduce the number of digits of N by computing the sum of all the digits to get a new number. If this new number exceeds 9, then sum the digits of this new number to get another number and continue this way until a single digit value is obtained as the ‘digit sum’. The task here is to find out whether the result of the digit sum done this way is ‘1’ or not. If the result is 1 return UNO else not.
Input : 254
output : not
Input : 235
output : UNO
Explation :
1. 254 = 2+5+4 = 11
2. 11>9
3. 11 = 1+1 = 2
4. 2<9 but not 1 so
5. output "NOT"
1. 235 = 2+3+5 =10
2. 10>9
3. 10 = 1+0 = 1
4. 1<9 and sum=1 so
5. output "UNO"
Code :
Comments
Post a Comment