Print prime numbers from 2 to 20

Ddd
Posted by Ddd under C# category on | Points: 40 | Views : 3026
//Print prime numbers from 2 to 20
using System;
class abc
{
static void Main()
{
int num,i,factor;
bool isprime;
for(num=2;num<20;num++)
{
isprime=true;
factor=0;
//check if the number is evenly divisible
for(i=2;i<=num/2;i++)
{
if (num% i==0)
{
isprime=false;
factor=i;
}
}
if(isprime==true)
{
Console.WriteLine(num+"----"+"is prime");
}
}
}
}

Comments or Responses

Login to post response