13,042,819 members (77,552 online)
Rate this:
See more:
how do i print prime and not prime number from 300 to 400 by using for loop and if statement.
Posted 12-Feb-13 16:48pm

Rate this:

## Solution 1

You take a paper, a pen and you write : 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397
:-)

more seriously here is a function to check if a number is a prime or not but beware you can only use it with relatively small numbers as it is not particularly optimized...

```public static bool IsPrime(this int number)
{
return (Enumerable.Range(1,number).Where(x => number % x == 0).Count() == 2);
}```
Rate this:

## Solution 2

Hello, this is logic to find out prime numbers between 300 to 400.

```namespace prime_number_series
{
class Program
{
static void Main(string[] args)
{
for (int i = 300; i <= 400; i++)
{
int count1 = 0;
int count2 = 0;
for (int k = 301; k < i - 1; k++)
{
int rem = i%k;
if (rem == 0)
{
count1++;
}
else
{
count2++;
}
}
if (count1 == 0)
{
Console.Write("{0} \t",i);
}

}

}
}

}```

Top Experts
Last 24hrsThis month
 Satya Prakash Swain 170 ppolymorphe 115 OriginalGriff 105 LuxGiammi 80 Karthik Bangalore 75
 OriginalGriff 4,255 RickZeeland 1,834 ppolymorphe 1,494 F-ES Sitecore 1,483 Dave Kreskowiak 1,309