Showing posts with label number which is divisible by self and by 1 only. Show all posts
Showing posts with label number which is divisible by self and by 1 only. Show all posts

19 September 2011

Prime No. in console apps

class Prime
{
static void Main(string[] args)
{
int j = 0;
int count = 0;
Console.WriteLine("Plz enter a number: ");
int n =int.Parse( Console.ReadLine() );
Console.WriteLine("The Prime no's are:");
for (int i = 2; i <= n; i++)
{
for (j = 2; j <= i; j++)
{
if (i % j == 0)
{
break;
}
}
if (i == j)
{
Console.WriteLine(i);
count++;
}
}
Console.WriteLine();
Console.Write("Total Prime No's: "+count);
Console.ReadLine();
}