Express an odd number as sum of prime numbers | CPP program to express N as sum of at - most three prime numbers . ; Function to check if a number is prime or not . ; Prints at most three prime numbers whose sum is n . ; if ( isPrime ( n ) ) CASE - I ; else if ( isPrime ( n - 2 ) ) CASE - II ; else CASE - III ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPrime ( int x ) { if ( x == 0 x == 1 ) return false ; for ( int i = 2 ; i * i <= x ; ++ i ) if ( x % i == 0 ) return false ; return true ; } void findPrimes ( int n ) { cout << n << endl ; cout << 2 << " ▁ " << n - 2 << endl ; { cout << 3 << " ▁ " ; n = n - 3 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPrime ( i ) && isPrime ( n - i ) ) { cout << i << " ▁ " << ( n - i ) ; break ; } } } } int main ( ) { int n = 27 ; findPrimes ( n ) ; return 0 ; }