Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:08:46+00:00 2026-06-01T19:08:46+00:00

I want to write some code which takes any positive, even number (greater than

  • 0

I want to write some code which takes any positive, even number (greater than 2) and gives me the smallest pair of primes that sum up to this number.
I need this program to handle any integer up to 9 digits long.

My aim is to make something that looks like this:

Please enter a positive even integer ( greater than 2 ) :
10
The first primes adding : 3+7=10.
Please enter a positive even integer ( greater than 2 ) :
160
The first primes adding : 3+157=160.
Please enter a positive even integer ( greater than 2 ) :
18456
The first primes adding : 5+18451=18456.

I don’t want to use any library besides stdio.h. I don’t want to use arrays, strings, or anything besides for the most basic toolbox: scanf, printf, for, while, do-while, if, else if, break, continue, and the basic operators (<,>, ==, =+, !=, %, *, /, etc…).
Please no other functions especially is_prime.

I know how to limit the input to my needs so that it loops until given a valid entry.

So now I’m trying to figure out the algorithm.

I thought of starting a while loop like something like this:

  #include <stdio.h>
long first, second, sum, goldbach, min;
long a,b,i,k; //indices

int main (){

    while (1){
        printf("Please enter a positive integer :\n");
        scanf("%ld",&goldbach);
        if ((goldbach>2)&&((goldbach%2)==0)) break;
        else printf("Wrong input, ");
        }

    while (sum!=goldbach){
        for (a=3;a<goldbach;a=(a+2))
            for (i=2;(goldbach-a)%i;i++)
                first = a;
        for (b=5;b<goldbach;b=(b+2))
            for (k=2;(goldbach-b)%k;k++)
        sum = first + second;
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:08:48+00:00Added an answer on June 1, 2026 at 7:08 pm

    Have a function to test primality

    int is_prime(unsigned long n)
    

    And then you only need to test whether a and goldbach - a are both prime. You can of course assume a <= goldbach/2.

    And be sure to handle goldbach = 4 correctly.

    If the requirements don’t allow defining and using your own functions, ignore them first. Solve the problem using any functions you deem helpful and convenient. When you have a working solution using disallowed functionality, then you start replacing that with allowed constructs. Self-defined functions can be inlined directly, replacing the return with an assignment, so instead of if (is_prime(a)), you have the code to determine whether a is prime and instead of returning the result you assign it is_prime = result; and test that variable if (is_prime). Where you have used library functions, reimplement them yourself – efficiency doesn’t matter much – and then inline them too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i just join phonegap, i want a built test application. i write some code
I want to write some games, but I don't have any game development experience.
I am attempting to write a two-pass algorithm incorporating some legacy code. I want
I want to reuse some code I wrote to add some functionality to a
I want to write some debugging output to the log to review it with
I want to write some text directly to a file using Flex 3 /
I want to write some bogus text in a file (helloworld text in a
I want to write some test cases for my web app, but stuck at
At the end of a simulation, I want to write some results as an
I want to write a program to hash some data and preferably i would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.