Prime Number Program in C#
Prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers can't be divided by other numbers than itself or 1. For example 2, 3, 5, 7, 11, 13, 17, 19, 23.... are the prime numbers.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number, i, m = 0, flag = 0;
Console.WriteLine("PLEASE ENTER THE NUMBER TO CHECK PRIME NUMBER");
number = int.Parse(Console.ReadLine());
m = number / 2;
for(i=2;i<=m;i++)
{
if(number%i==0)
{
Console.WriteLine("NUMBER IS NOT PRIME");
flag = 1;
break;
}
}
if(flag==0)
{
Console.WriteLine("NUMBER IS PRIME");
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number, i, m = 0, flag = 0;
Console.WriteLine("PLEASE ENTER THE NUMBER TO CHECK PRIME NUMBER");
number = int.Parse(Console.ReadLine());
m = number / 2;
for(i=2;i<=m;i++)
{
if(number%i==0)
{
Console.WriteLine("NUMBER IS NOT PRIME");
flag = 1;
break;
}
}
if(flag==0)
{
Console.WriteLine("NUMBER IS PRIME");
}
Console.ReadLine();
}
}
}
Comments