//Prime Number Test
public class Test{
public static void Main(){
try{
PrintPrime(100,400);
}catch(System.Exception ex){
System.Console.WriteLine(ex.Message);
}
}
//print prime number between low and High
static void PrintPrime(int low, int high){
string strErrMsg = "";
if(low < 0 || high< 0){
strErrMsg = "Natural number must be 1+ integer!";
throw new System.ArgumentOutOfRangeException("",strErrMsg);
}
if(high > int.MaxValue || low < int.MinValue){
strErrMsg = "Integer Value is out of range !";
throw new System.ArgumentOutOfRangeException("",strErrMsg);
}
int ix = low;
for (;ix <= high; ix++){
if(IsPrime(ix)){
System.Console.Write(ix + "\t");
}
}
}
// Is it a prime number
// returns : ture, is prime number
// : false,is not prime number
static bool IsPrime(int n){
bool blnReturn = true;
if (n <= 1){
blnReturn = false;
}
for(int i=2; i<Sqrt(n); i++){
if ( n % i == 0){
blnReturn = false;
break;
}
}
return blnReturn;
}
//my Sqrt
static double Sqrt(double num ){
double E = 0.0000001f;
double d = num /2;
while (Abs(num - d * d) > E){
d = (d + num / d) / 2;
}
return d;
}
//my Abs
static double Abs(double d){
if ( d >= 0) {
return d;
}
else{
return -d;
}
}
}