Goldbach's Conjecture solution using c language --programming_info.problem5

Goldbach's Conjecture

This above example is just a reference picture. don't
think it as an input of an array.
you can give your own input.

/*Goldbach's conjecture is a rule in math that states the following: every even number greater than 2 can be expressed as the sum of two prime numbers.*/

#include<stdio.h>
#include<math.h>

int prime (int n)
{
  int flag = 0;
  for(int i = 2 ; i <= sqrt(n); i ++ )
  {
    if(n % i == 0)
    {
      flag = 1;
      break ;
    }
  }
  if(!flag)
  return 1;
  else
  return 0;
}

int main()
{
  int m;
  scanf("%d", & m);
  for(int i = 2 ; i <= (m )/2 ; i ++)
  {
    int k = i , l = m - i;
    if(prime(k) && prime(l))
    {
    printf("%d  +  %d\n",k , l);
    }
  }
}
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support