using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int l, h, i, c;
Console.Write("\n Enter the lowest range : ");
l = int.Parse(Console.ReadLine());
Console.Write("\n Enter the highest range : ");
h = int.Parse(Console.ReadLine());
Console.Write("\n Prime numbers are : ");
while (l <= h)
{
c = 0;
for (i = 2; i <= l; i++)
{
if (l % i == 0)
c++;
}
if (c < 2)
Console.Write(" " + l);
l++;
}
Console.ReadLine();
}
}
}
Output

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int l, h, i, c;
Console.Write("\n Enter the lowest range : ");
l = int.Parse(Console.ReadLine());
Console.Write("\n Enter the highest range : ");
h = int.Parse(Console.ReadLine());
Console.Write("\n Prime numbers are : ");
while (l <= h)
{
c = 0;
for (i = 2; i <= l; i++)
{
if (l % i == 0)
c++;
}
if (c < 2)
Console.Write(" " + l);
l++;
}
Console.ReadLine();
}
}
}
Output
No comments:
Post a Comment