Hi everyone,

Its my first post, and by the way its my first semester studying C language. And it's the first programming experience.

I was asked to write a program that , for each even number between 700 and 1100 , it lists its equivalent value as a sum of primes (assuming godbach was right so far!! lol ) ..the thing is that i couldn't do it using ordinary loops. so i used an array in which i have stored the primes i want to process.

For that said, Can anyone tell me why the output of my program outputs only relatively bigger primes as operands for the sum. I mean it's correct but why it skip situations in which small prime numbers can be used like 3.

700 = 419 + 281 ya right but why not 700 = 23 + 677 .

here is my code

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define start 700
#define finish 1100
int is_prime(int);
int check(int);
int main(){
for(int i = start ; i <= finish ; i += 2){
check(i);
}
system("PAUSE");
return(0);
}
int is_prime(int n){
for(int i = 2 ; i <= sqrt(n) ; i++){
if(!(n%i))
return(0);
}
return(1);
}
int check(int x){
int k[x];
int j = 0;
for (int i = 1 ; i < x ; i += 2){
if (is_prime(i)){
k[j] = i;
j++;
}
}
for (int n = 0 ; n < j ; n++){
for (int a = 0 ; a <= j/2 ;a++){
if (x == k[n]+k[a]){
printf("%d = %d + %d\n",x,k[n],k[a]);
return (0);
}
}
}
}