C# Program toward check entered number is prime or composite
Program Statement:
Write a program that takes an integer as an input from user furthermore prints if it is a prime or composite number.
Solution:
static void Main(string[] args)
{
int num, i;
Console.WriteLine("Enter the number toward check number is prime or composite");
num=Convert.ToInt32(Console.ReadLine());
i = 2;
while (i <= num - 1)
{
if (num % i == 0)
{
Console.WriteLine("composite number: "+num);
break;
}
i++;
}
if (i == num)
Console.WriteLine("prime number: " + num);
Console.ReadLine();
}