C# Program to check number is prime or composite

C# Program to check entered number is prime or composite 

Program Statement:
Write a program that takes an integer as an input from user and prints if it is a prime or composite number.

Solution:
 static void Main(string[] args)
{
int num, i;
Console.WriteLine("Enter the number to 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();

}


Komentar

Postingan populer dari blog ini

All India BSNL Nodal officer Contact Information..!!!

Video & Photo Gallery: Unboxing ORICO D10000 Scharge Polymer Power Bank

How to Automatically Shrink url of ADF.ly || Earn Money By ADF.ly