In this C# tutorial we were checking whether number is prime or not . Here we are taking two variables "num" for number and and "a" for counter variable. Now, lets get started!!
Note: Prime number is the number which divides by itself for e.g 2, 7, 11, 17....
Note: Prime number is the number which divides by itself for e.g 2, 7, 11, 17....
using System;
class prime
{
public static void Main(String []args)
{
int num;
Console.WriteLine("Please enter number : ");
num=Convert.ToInt32(Console.ReadLine());
for (int a = 2; a <= num / 2; a++)
{
if (num % a == 0)
{
Console.WriteLine(num + " is not prime number");
return;
}
}
Console.WriteLine(num + " is a prime number");
}
}
0 comments:
Post a Comment