text: programming logic to find whether the given number is prime or not in c or c#?   while sieve_of_eratosthenes is good for finding all prime upto a power, it is not good for finding whether a given number is prime. in this case modulas method is good. but the algorithm of first answer is inefficien( because it checks upto x-1 while checking upto square root of x is sufficient). a better algorithm is  int isprime(x){ for(i=0;i<(int)sqrt(x);i++) if(x%i)==0 return 0;  return 1; }