Number of non | A naive C ++ solution to count solutions of a + b + c = n ; Returns count of solutions of a + b + c = n ; Initialize result ; Consider all triplets and increment result whenever sum of a triplet is n . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countIntegralSolutions ( int n ) { int result = 0 ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n - i ; j ++ ) for ( int k = 0 ; k <= ( n - i - j ) ; k ++ ) if ( i + j + k == n ) result ++ ; return result ; } int main ( ) { int n = 3 ; cout << countIntegralSolutions ( n ) ; return 0 ; }