using System;
class abc
{
int num, count;
public void prime()
{
Console.WriteLine("enter the number to find it is prime or not");
num = int.Parse(Console.ReadLine());
for (int i = 2; i <= num; i++)
{
if ((num % i) == 0)
{
count = count + 1;
}
}
if (count == 1)
{
Console.WriteLine(num + " is a prime.");
}
else
{
Console.WriteLine(num + " is not a prime.");
}
Console.ReadKey();
}
}
class prim
{
public static void Main(string[] args)
{
abc a = new abc();
a.prime();
}
}
Output
class abc
{
int num, count;
public void prime()
{
Console.WriteLine("enter the number to find it is prime or not");
num = int.Parse(Console.ReadLine());
for (int i = 2; i <= num; i++)
{
if ((num % i) == 0)
{
count = count + 1;
}
}
if (count == 1)
{
Console.WriteLine(num + " is a prime.");
}
else
{
Console.WriteLine(num + " is not a prime.");
}
Console.ReadKey();
}
}
class prim
{
public static void Main(string[] args)
{
abc a = new abc();
a.prime();
}
}
Output
No comments :
Post a Comment