C Programming Code Examples C > Mathematics Code Examples Check Whether a Number can be Expressed as Sum of Two Prime Numbers Check Whether a Number can be Expressed as Sum of Two Prime Numbers To accomplish this task, checkPrime() function is created. The checkPrime() returns 1 if the number passed to the function is a prime number. #include <stdio.h> int checkPrime(int n); int main() { int n, j, flag = 0; printf("Enter a positive integer: "); scanf("%d", &n); for(j = 2; j <= n/2; ++j) { // condition for j to be a prime number if (checkPrime(j) == 1) { // condition for n-j to be a prime number if (checkPrime(n-j) == 1) { // n = primeNumber1 + primeNumber2 printf("%d = %d + %d\n", n, j, n - j); flag = 1; } } } if (flag == 0) printf("%d cannot be expressed as the sum of two prime numbers.", n); return 0; } // Function to check prime number int checkPrime(int n) { int j, isPrime = 1; for(j = 2; j <= n/2; ++j) { if(n % j == 0) { isPrime = 0; break; } } return isPrime; }