Saturday, August 31, 2013

Write the prime Number code which output like this?


using System;
using System.Collections.Generic;

namespace Csharp
{
public class MainTest
{
static bool IsPrime(int num)
{
for (int i = 2; i <= Math.Sqrt(num); i++)
{
if (num % i == 0) return false;
}
return true;
}
static void Main(string[] args)
{
int num = 0;
//Count how many prime numbers are generated
int counter = 0;
Console.WriteLine("Please input a number:");
num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Results are:");
for (int i = 2; i <int.MaxValue; i++)
{
if (IsPrime(i))
{
Console.WriteLine(i);
counter++;
if (counter == num)
{
break;
}
}
}
}
}
}



If you think one reply solves your problem, please mark it as An Answer , if you think someone's reply helps you, please mark it as a Proposed Answer



Help by clicking:

Click here to donate your rice to the poor

Click to Donate

Click to feed Dogs & Cats




Found any spamming-senders? Please report at: Spam Report


No comments:

Post a Comment