Could someone take a look and fix it please. I at a wall with bugs, and i just d
ID: 672616 • Letter: C
Question
Could someone take a look and fix it please. I at a wall with bugs, and i just dont know.
its supposedly should do the following
Write a c program to calculate all the possible pairs of two prime numbers that add up to the given integer. This program reads a positive integer from user and checks whether that number can be expressed as the sum of two prime numbers. To perform this task, two user-defined functions named prime and is sum of two primes are required. Function prime checks if a given integer is prime; and is sum of two primes checks whether a number can be expressed as the sum of two prime numbers. Following is a sample output: Enter a positive integer:
34 = 3 + 31
34 = 5 + 29
34 = 11 + 23
34 = 17 + 17
Thank you for your help!!!
#include<stdio.h>
int Prime(int input);
void is_sum_of_two_primes(int input);
int main(void)
{
int input;
printf("Please enter a positive integer here: ");
scanf("%d",&input);
is_sum_of_two_primes(input);
return 0;
}
int Prime(int input)
{
int i;
for(i= 2; i<input/2;i++)
{
if(input%i == 0)
return Prime;
}
void is_sum_of_two_primes( int input);
{
for(i=2;i<input/2+1;i++)
{
if(Prime(i)&&Prime(input-i))
printf("%d = %d + %d ",input,i,input-i);
}
}
Explanation / Answer
#include<stdio.h>
int Prime(int input);
void is_sum_of_two_primes(int input)
{
for(int i=2;i<input/2+1;i++)
{
if(Prime(i)&&Prime(input-i))
printf("%d = %d + %d ",input,i,input-i);
}
}
int main(void)
{
int input;
printf("Please enter a positive integer here: ");
scanf("%d",&input);
is_sum_of_two_primes(input);
return 0;
}
int Prime(int input)
{
int i;
for(i= 2; i<input/2;i++)
{
if(input%i == 0)
return 0;
}
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.