1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PROGRAMMiNG EXERCiSES

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

  1. Luisa Mia Peralta

    Luisa Mia Peralta New Member

    Joined:
    Sep 25, 2011
    Messages:
    7
    Likes Received:
    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 ..



    thanks in advance to those who will answer this :DD
     
  2. sh2ka

    sh2ka New Member

    Joined:
    Sep 20, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i need a free programing software please help
     
  3. madhupadikar

    madhupadikar New Member

    Joined:
    Oct 5, 2011
    Messages:
    1
    Likes Received:
    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);
    }
     

Share This Page