Sum of matrix element where each elements is integer division of row and column | C ++ program to find sum of matrix element where each element is integer division of row and column . ; Return sum of matrix element where each element is division of its corresponding row and column . ; For each column . ; count the number of elements of each column . Initialize to i - 1 because number of zeroes are i - 1. ; For multiply ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findSum ( int n ) { int ans = 0 , temp = 0 , num ; for ( int i = 1 ; i <= n && temp < n ; i ++ ) { temp = i - 1 ; num = 1 ; while ( temp < n ) { if ( temp + i <= n ) ans += ( i * num ) ; else ans += ( ( n - temp ) * num ) ; temp += i ; num ++ ; } } return ans ; } int main ( ) { int N = 2 ; cout << findSum ( N ) << endl ; return 0 ; }