using System.Collections.Generic;
class Program
{
public void prime(int num)
{
Boolean isPrime = true;
Console.WriteLine("the prime number between 1-{0} is: ",num);
for (int i = 0; i <= num; i++)
{
for(int j=2;j<=num;j++)
if (i != j && i % j == 0)
{
isPrime = false;
break;
}
if (isPrime == true)
{ Console.WriteLine("{0}", i); }
isPrime = true;
}
}
}
class pro
{
static void Main()
{
Console.WriteLine("www.promohack.blogspot.com");
int num;
Program obj = new Program();
string str;
Console.WriteLine("enter the number till which you want to show the prime number");
str=Console.ReadLine();
num=Convert.ToInt16(str);
obj.prime(num);
Console.ReadLine();
}
}
Thank You.
Comments
Post a Comment