-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex77.c
More file actions
51 lines (41 loc) · 651 Bytes
/
Copy pathex77.c
File metadata and controls
51 lines (41 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// express given number a sum of two prime number
// i + (x-i) = x is given number where i and x-i is a prime number
#include <stdio.h>
int nextprime(int);
int isprime(int);
int main()
{
int n,i;
printf("Enter a number\n");
scanf("%d",&n);
for( i = 1; i<=(n-i); i = nextprime(i))
{
if( isprime(n-i) )
{
printf("%d + %d = %d\n",i,n-i,n);
}
}
}
int isprime(int n)
{
int i;
for( i = 2; i<n; i++)
{
if (n%i==0)
{
return 0;
break;
}
}
if(i==n)
return 1;
}
int nextprime(int n)
{
int next = n+1;
while(!isprime(next))
{
next++;
}
return next;
}