Integer as a Sum of Two Prime Numbers

integer sum c prime numbers 5 years, 3 months ago
#include <stdio.h> int checkPrime(int n); int main() { int n, i, flag = 0; printf("Enter a positive integer: "); scanf("%d", &n); for(i = 2; i <= n/2; ++i) { // condition for i to be a prime number if (checkPrime(i) == 1) { // condition for n-i to be a prime number if (checkPrime(n-i) == 1) { // n = primeNumber1 + primeNumber2 printf("%d = %d + %d\n", n, i, n - i); flag = 1; } } } if (flag == 0) printf("%d cannot be expressed as the sum of two prime numbers.", n); return 0; } // Function to check prime number int checkPrime(int n) { int i, isPrime = 1; for(i = 2; i <= n/2; ++i) { if(n % i == 0) { isPrime = 0; break; } } return isPrime; }
884
Posted By
Tower of Hanoi in C
#include <stdio.h> 
void towerOfHanoi(int n, char from_rod, 
{ 
tower of hanoi c
Reshma
Program to print half pyramid using *
#include<stdio.h>
int main()
{
half pyramid c
Reshma
Program to print half pyramid using numbers
#include <stdio.h>
int main()
{
half pyramid using numbers c
Reshma
Armstrong Number in C
#include <stdio.h>
#include <math.h>
void main()
armstrong number c
Reshma
Program to print half pyramid using alphabets
#include <stdio.h>
int main()
{
pyramid alphabets c
Reshma
Inverted half pyramid using *
#include <stdio.h>
int main()
{
inverted pyramid c
Reshma
Program to Find Roots of a Quadratic Equation
#include <stdio.h>
#include <math.h>
int main()
roots of quadratic eon c
Reshma
GCD Using for loop and if Statement
#include <stdio.h>
int main()
{
gcd c
Reshma
GCD Using while loop and if...else Statement
#include <stdio.h>
int main()
{
gcd while c
Reshma
GCD for both positive and negative numbers
#include <stdio.h>
int main()
{
gcd c
Reshma
LCM using while Loop and if Statement
#include <stdio.h>
int main()
{
c lcm
Reshma
LCM Calculation by Finding GCD
#include <stdio.h>
int main()
{
c lcm using gcd
Reshma
Sum of Natural Numbers Using Recursion
#include <stdio.h>
int addNumbers(int n);
int main()
c sum of numbers
Reshma
Display Prime Numbers Between two Intervals
#include <stdio.h>
int main()
{
interval c prime
Reshma