C Program to Check if Number Can be Expressed as Sum of Two Prime Numbers

C Program to Check if Number Can be Expressed as Sum of Two Prime Numbers

Write C Program to Check if Number Can be Expressed as Sum of Two Prime Numbers

// C Program to Check if Number Can be Expressed as Sum of Two Prime Numbers

#include <stdio.h>
#include <stdbool.h>

int check_Prime(int n)
{
	int i;
	bool isprime = true;
	if(n==1 || n==0)
	{
		 isprime = false;
	}

	for(i = 2; i <= n/2; i++)
	{
		if(n%i == 0)
		{
			isprime = false;
			break;
		}
	}
	return isprime;
}

int main()
{
	int n, i, flag = 0;

	printf("Enter the Number :--> ");
	scanf("%d",&n);

	for(i = 2; i <= n; i++)
	{
		if(check_Prime(i))
		{
			if(check_Prime(n - i))
                printf("%d + %d = %d\n", i, n - i, n);
            flag = 1;
		}
	}
	if(!flag || n==2 || n==3)
	{
		printf("Cannot be expressed as sum of 2 positive numbers");
	}

	return 0;
}

Output:

Enter the Number :--> 18
5 + 13 = 18
7 + 11 = 18
11 + 7 = 18
13 + 5 = 18