Triplet with no element divisible by 3 and sum N | C ++ program to print a , b and c such that a + b + c = N ; Function to print a , b and c ; first loop ; check for 1 st number ; second loop ; check for 2 nd number ; third loop ; Check for 3 rd number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printCombination ( int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( i % 3 != 0 ) { for ( int j = 1 ; j < n ; j ++ ) { if ( j % 3 != 0 ) { for ( int k = 1 ; k < n ; k ++ ) { if ( k % 3 != 0 && ( i + j + k ) == n ) { cout << i << " ▁ " << j << " ▁ " << k ; return ; } } } } } } } int main ( ) { int n = 233 ; printCombination ( n ) ; return 0 ; }