Prime number
Last updated:
8/23/2020
⁃
Difficulty:
Easy
Write a program in C# which asks the user for an integer number and answers if it is a prime number or not.
Input
7
Output
Is prime
Solution
using System;
public class PrimeNumber
{
public static void Main(string[] args)
{
int x = Convert.ToInt32(Console.ReadLine());
int divider = 2;
while (x % divider != 0)
{
divider++;
}
if (divider == x)
{
Console.WriteLine("Is prime");
}
else
{
Console.WriteLine("Is not prime");
}
}
}