Python program to find the sum of odd digits of the product of two numbers.

Rajnilari2015
Posted by Rajnilari2015 under Python category on | Points: 40 | Views : 1822
Let us say we have two numbers num1 = 19 and num2 = 65. The product of num1 and num 2 is 1235.
The odd numbers are 1,3 and 5 and their sum is 9. The below program will do so

from System import *
from System.Linq import *
from System.Numerics import *

class Program(object):
def Main(args):
num1 = 19
num2 = 65
#Approach 1
Console.WriteLine("The sum of odd digits of the product of {0} and {1} is {2}", num1, num2, (num1 * num2).ToString().ToCharArray().Where().Select().Sum())
#Approach 2
Console.WriteLine("The sum of odd digits of the product of {0} and {1} is {2}", num1, num2, Array.ConvertAll((num1 * num2).ToString().ToCharArray().Where().ToArray(), ).Sum())
Console.ReadKey()

Main = staticmethod(Main)


Output
------

The sum of odd digits of the product of 19 and 65 is 9

Comments or Responses

Login to post response