jeudi 17 décembre 2015

Wrong output for prime numbers

#include <stdio.h>

int main()
{
    int i, n, c, p;

    printf("enter\n");
    scanf("%d", n);
    c = find(n);
    if (c == 1)
    {
        printf("no. is not prime");
    }
    else
    {
        printf("no. is prime");
    }

}

find(int n)
{
    int i = 2, p;

    while (i < n)
    {
        p = n % i;
        printf("value of p%d", p);
        if (p == 0)
        {

            return 1;
        }
        i = i + 1;
    }
    return 2;
}

.................................... Above program giving me 'not a prime number' output for all inputs...also the value of p is always zero and this shouldn't be the case... Please help...badly stuck...

Aucun commentaire:

Enregistrer un commentaire