Sum of an array of large numbers | Function to prthe result of the summation of numbers having K - digit ; Reverse the array to obtain the result ; Print every digit of the answer ; Function to calculate the total sum ; Stores the array of large numbers in integer format ; Convert each element from character to integer ; Stores the carry ; Stores the result of summation ; Initialize the sum ; Calculate sum ; Update the sum by adding existing carry ; Store the number of digits ; Increase count of digits ; If the number exceeds 9 , Store the unit digit in carry ; Store the rest of the sum ; Append digit by digit into result array ; Append result until carry is 0 ; Print the result ; Driver Code ; Given N array of large numbers
def printResult ( result ) : NEW_LINE INDENT result = result [ : : - 1 ] NEW_LINE i = 0 NEW_LINE while ( i < len ( result ) ) : NEW_LINE INDENT print ( result [ i ] , end = " " ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT def sumOfLargeNumbers ( v , k , N ) : NEW_LINE INDENT x = [ [ ] for i in range ( 1000 ) ] NEW_LINE for i in range ( k ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT x [ i ] . append ( ord ( v [ i ] [ j ] ) - ord ( '0' ) ) NEW_LINE DEDENT DEDENT carry = 0 NEW_LINE result = [ ] NEW_LINE for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT sum = 0 NEW_LINE for j in range ( k ) : NEW_LINE INDENT sum += x [ j ] [ i ] NEW_LINE DEDENT sum += carry NEW_LINE temp = sum NEW_LINE count = 0 NEW_LINE while ( temp > 9 ) : NEW_LINE INDENT temp = temp % 10 NEW_LINE count += 1 NEW_LINE DEDENT l = pow ( 10 , count ) NEW_LINE if ( l != 1 ) : NEW_LINE INDENT carry = sum / l NEW_LINE DEDENT sum = sum % 10 NEW_LINE result . append ( sum ) NEW_LINE DEDENT while ( carry != 0 ) : NEW_LINE INDENT a = carry % 10 NEW_LINE result . append ( a ) NEW_LINE carry = carry // 10 NEW_LINE DEDENT printResult ( result ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT K = 10 NEW_LINE N = 5 NEW_LINE arr = [ "1111111111" , "1111111111" , "1111111111" , "1111111111" , "1111111111" ] NEW_LINE sumOfLargeNumbers ( arr , N , K ) NEW_LINE DEDENT