Sum of Digits – Largest Integer

The program must accept N integers as the input. The program must print the sum of the digits of the largest integer among the N integers as the output.

Boundary Condition(s):
1 <= N <= 100
1 <= Each Integer Value <= 1000

Input Format:
The first line contains the integer N.
The second line contains N integers separated by space(s).

Output Format:
The first line contains the sum of the digits of the largest integer among N integers.

Example Input/Output 1:
Input:
6
98 74 85 23 58 21

Output:
17

Explanation:
The largest integer is 98.
So the sum of the digits of 98 is 17 (9 + 8).
Hence the output is 17

Example Input/Output 2:
Input:
9
401 884 8 203 123 950 475 520 193

Output:
14

def sum_of(number):
    s=0
    for digit in str(number):
        s+=int(digit)
    return s

number=int(input())
list_main=[int(digit) for digit in input().split()]
larget_digit=max(list_main)
print(sum_of(larget_digit))

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.