Thursday, March 20, 2008

Find Prime Number at Fastest Speed.

Introduction to the Prime Numbers:
A composite number is a positive integer which has a positive divisor other than one or itself. By definition, every integer greater than one is either a prime number or a composite number. The number one is considered to be neither prime nor composite.

For example,the integer 14 is a composite number because it can be factored as 2 × 7.

The first 15 composite numbers are
4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, and 25.

The firs 5 prime numbers are 2,3,5,7,11

Problem Description:I have find many programs which find the prime numbers or gives you whether the number is prime or not, or gives collection of numbers which are prime from the given number range but the problem in those programs are very slow and becomes Massey (and also sometimes hang your system)when you give the large number 100000 to find out prime number up to that number.

one of my colleague name mayur has suggested algorithm of find the prime numbers by the fastest way.The algorithm of Sieve of Eratosthenes pleast visit here.

C# code for that algorithm is given below.Try it and compare it with your program.

using System.Collections;

int range= 1000000;
BitArray numbers = new BitArray(range, true);

for(int i = 2; i < range; i++)
if(numbers[i])
{
for(int j = i * 2; j < range; j += i)
numbers[j] = false;
}

int primes = 0;

for(int i = 1; i < range; i++)
if(numbers[i])
{
primes++;
//Console.Out.WriteLine(i);
}

Console.Out.WriteLine();
Console.Out.WriteLine(primes + " out of " + range + " prime numbers found.");
Console.In.ReadLine();

The Older and simple program which was done in my school days.


ArrayList primeList = new ArrayList();

for(int i = 2; i < 100; i++)
{
bool divisible = false;

foreach(int number in primeList)
if(i % number == 0)
divisible = true;

if(divisible == false)
primeList.Add(i);
}

If you dare to beat above program then pleas visit this and send me your program after implementation best of luck guys.

Monday, January 21, 2008

Download LinqPad of Joseph Albahari



Hi!!

"C# 3.0 In Nutshell" a book written by Albhari brothers is very interesting contains 24 chapters and will be very helpfull who would like to learn C# 3.0. you can download it's code listings from here.

LINQPad is written by Joseph Albahari and can be download from here.

.NET Framework 3.5 Namespace Poster Download

Hi!!
I am very happy to inform you that now Microsoft .Net Framework 3.5 Namespace poster is available to download in many formats so who are interested to download it they can visit Brad Abrams blog or visit here to see or download the .NET Framework 3.5 Namespace Poster.

Saturday, January 19, 2008

Story Behind My Blog's Title

Hello Readers,

I have read about the history about the C# on the James Kovacs' Weblog



see above, the photograph of the Building -42,Redmond,WA where C# is developed in one room for four years by Andrew Hejlsberg and his team.

Project Cool is code name of C#.

I am very much impressed by C# language hence I have choosen C# - "Project Cool" Building-42 Redmond as my blog's title and also dedicated my first post to it.