Another beginning function
Hi:
Ran into another problem in studying my programing. This program is designed to compute a number of primes. Instead of computing any primes, however, it throws a segmentation block. I suspect that it may because I am returning 1 and 0 instead of true and false, but I did that because when I return true and false I get these errors.
ThousandthPrime.c:10:10: error: ‘false’ undeclared (first use in this function)
ThousandthPrime.c:10:10: note: each undeclared identifier is reported only once for each function it appears in
ThousandthPrime.c:20:9: error: ‘true’ undeclared (first use in this functio
Code:
//ThousandthPrime: Calculate the thousandthprime.
#include <stdio.h>
//primality function which will determine if a number is prime.
long Primality(long n)
{
//check to see if the number is a multiple of 2(ie the number is even) and is not equal to 2
if(n % 0 && n != 2)
{
return 0; //if the number is even or equal to 2, return false and do not count these numbers
}//end if
//once we determine that a number is not even or equal to 2, we can check the odds.
for(long i = 3; i * i <= n; i += 2)
{
if(n % i == 0)
{
return 0;
}//end if
}//end for
return 1;
}//end function primality
int main()
{
long primes = 0;// counts the number of primes for us.
long n = 1; //variable that we will run through primality function
long y = 0; //variable input by the user to tell how many primes to find.
printf("Please enter a number(n), and the program will return with the \"nth\" number of primes");
scanf("%ld", y);
//while loop calls the primality functions until "y" primes are found
while(primes < y)
{
n++;
Primality(n);
if(Primality(n))
{
printf("%ld", n);
primes++;
}//end if
}//end while
printf("I found %ld primes %ld is the \"nth\" prime", primes, n);
}//end main
Code:
Please enter a number(n), and the program will return with the "nth" number of primes: 3
Segmentation fault (core dumped)
What am I doing wrong?