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");
}
}
}
}
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 14, 2014, 9:51 AM