Home » Check Number can be Expressed as the Sum of Two Prime Numbers

# Check Number can be Expressed as the Sum of Two Prime Numbers

Learn about Check Number can be Expressed as the Sum of Two Prime Numbers in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

#### Check Number can be Expressed as the Sum of Two Prime Numbers

Program:

``````#include<stdio.h>
int check(int a);
int main()
{
int n, j, flag;

printf("Enter a number: ");
scanf("%d",&n);

for(j=2;j<=n/2;j++)
{

if(check(j)==0)
{
if(check(n-j)==0)
{

printf(" %d + %d = %d\n", j, n-j, n);
flag=0;
}
}
}

if(flag==1)
printf("Can't be expressed as sum of two prime Numbers.\n");

return 0;
}

int check(int a)
{
int i, flag=0;

for(i=2;i<=a/2;i++)
{
if(a%i==0)
flag++;
}

if(flag==0)
return 0;
else
return 1;
}``````

Output:

Enter a number: 5
2 + 3 = 5

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.