Check the Number is Prime or Not

Mar 14 2014 9:06 AM
Please Check the following code i am facing an error in this code below
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Prime2
{
class CheckPrime
{
//Return true If x is Prime
#region IsPrimebooleanLogic
public bool IsPrime(int x)
{
for (int i = 2; i <= x / i; i++)
{
if ((x % i) == 0)
{
return false;
}
else
return true;
}
}
#endregion
}
class CheckPrimeDemo
{
static void Main(string[] args)
{
CheckPrime opt = new CheckPrime();
 int end;
Console.WriteLine("Enter the Ending Number for Prime number search");
end = int.Parse(Console.ReadLine());
for (int i = 1; i < 10; i++)
{
if (opt.IsPrime(i))
Console.WriteLine(i+ " is Prime Number");
else
Console.WriteLine(i + " is Not Prime Number");
}
}
}
}
 

Answers (1)