# PROGRAMMiNG EXERCiSES

Discussion in 'C' started by Luisa Mia Peralta, Sep 25, 2011.

1. ### Luisa Mia PeraltaNew Member

Joined:
Sep 25, 2011
Messages:
7
0
Trophy Points:
0
guysss kindly help me with these problems .. :pleased:

4.1)Write a function int is_prime (int n) that returns 1 if n is prime and 0 otherwise.

Hint: if k and n are positive integer, then k divides n if and only if n % k has value 0.

4.2) A famous conjecture, called the GOLDBACH conjecture, says that every even integer n greater than 2 has the property that it is the sum of two prime numbers. Computers have been used extensively to test this conjecture. No counter example has been found. Write a program that will prove that the conjecture is true for all the even integers between two input parameters, I and j, and returns a value of 1if and only if I and j are relatively prime. Otherwise, rel_prime should return a value 0 ..

2. ### sh2kaNew Member

Joined:
Sep 20, 2011
Messages:
1
0
Trophy Points:
0

Joined:
Oct 5, 2011
Messages:
1
0
Trophy Points:
0

Code:
```#include<stdio.h>
int is_prime(int n);
int main()
{
int n,flag;
scanf("%d",&n);
flag=is_prime(n);
if(flag==1)
{
printf("prime");
}
else
{
printf("not prime");
}

}
int is_prime(int n)
{
int i,flag=1;
if(n==1)
{
flag=0;
return(flag);
}
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
return(flag);
}```