How to get Prime Number in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int i, j;
Console.WriteLine("Enter a number");
i = Int32.Parse(Console.ReadLine());
for (j = 2; j < i; j++)
{
if (i % j == 0)
{
Console.WriteLine("{0} is not prime", i);
break;
}
}
if (j == i)
{
Console.WriteLine("{0} is prime", i);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int i, j;
Console.WriteLine("Enter a number");
i = Int32.Parse(Console.ReadLine());
for (j = 2; j < i; j++)
{
if (i % j == 0)
{
Console.WriteLine("{0} is not prime", i);
break;
}
}
if (j == i)
{
Console.WriteLine("{0} is prime", i);
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment