The C language and the Java language version of the Goethe-Bach conjecture (give the sum of two primes for any even number greater than 6)

Source: Internet
Author: User

C language version

#include <stdio.h>
int isprime (int n)
{
	int j,x;
	for (j=2;j<n;j++)
	if (n%j==0)	
	{
		x=0;
		break;
	else
	x=1;
	return x;
}
int main ()
{
	int n,i;
	printf ("Please input a even number (>6):");
	scanf ("%d", &n);
	while (n<6| | n%2!=0)
	{
		printf ("Bad number! Please input again: ");
		scanf ("%d", &n);
	}
	For (i=3;i< (N/2); i++)
	{
		if (IsPrime (i)!=0&&isprime (n-i)!=0)
		printf ("%d=%d+%d\n", N,i, n-i);
	}

Java language edition

import Java.util.Scanner;
	public class Prime {public int n,i;
		public int IsPrime (int n) {int J, x = 0;
				for (j = 2; J < N; j +) if (n% j = = 0) {x = 0;
			Break
		else x = 1;
	return x;
		public static void Main (string[] args) {Prime num =new Prime ();
		System.out.printf ("Please input a even number (>6):");
		Scanner input1 = new Scanner (system.in);
		int n = input1.nextint (); while (N < 6 | |-n% 2!= 0) {System.out.printf ("bad number!
			Please input again: ");
		n = input1.nextint (); for (int i = 3; I < (N/2); i++) {if (Num.isprime (i)!= 0 && num.isprime (n-i)!= 0) System.out.pr
		INTLN (n + "=" + i + "+" + (n-i)); }
	}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.