Sum of the products of same placed digits of two numbers | C ++ program to calculate the sum of same placed digits of two numbers ; Function to find the sum of the products of their corresponding digits ; Loop until one of the numbers have no digits remaining ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sumOfProductOfDigits ( int n1 , int n2 ) { int sum = 0 ; while ( n1 > 0 && n2 > 0 ) { sum += ( ( n1 % 10 ) * ( n2 % 10 ) ) ; n1 /= 10 ; n2 /= 10 ; } return sum ; } int main ( ) { int n1 = 25 ; int n2 = 1548 ; cout << sumOfProductOfDigits ( n1 , n2 ) ; }