Overview:
In this article i would like to present a publish a program for 1 to n prime numbers.
Description:
Prime Number:If a number is divisible by 1 and itself is known as a PrimeNumber.Remember 2 is termed as even primenumber
E.G:2,3,5,7,11,13,17,19...........................................
-->
Code:In this article i would like to present a publish a program for 1 to n prime numbers.
Description:
Prime Number:If a number is divisible by 1 and itself is known as a PrimeNumber.Remember 2 is termed as even primenumber
E.G:2,3,5,7,11,13,17,19...........................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1
{
class Program
{
static void Main(string[] args)
{
int i,j,n=0,n1=0;
Console.WriteLine("Enter The n value" );
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Prime Numbers are:");
for(i=2;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
{
n1++;
}
}
if(n1==2)
Console.WriteLine(i);
n1=0;
}
Console.ReadLine();
}
}
}
OutPut:
1 comment:
Why use n1=0;Last
Post a Comment