public class Program
{
//Program Working Correctly
public static void Main(string[] args)
{
Console.WriteLine("Enter the Number : ");
int num = int.Parse(Console.ReadLine());
Boolean isPrime = true;
for (int i = 2; i <= num; i++)
{
for (int j = 2; j <= num; j++)
{
if (i != j && i % j == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
Console.WriteLine(i);
}
isPrime = true;
}
}
}
Result:
Enter the Number : 10
2
3
5
7
This program finds the prime numbers whatever number you input my question is I want to fetch the prime number with the index number.
For example: I enter the index number 3 in index number 3 it must return the 7 coz 7 is the prime number which is placed in the index number 3.
So how to fetch the prime number value with the index number?