Student Of Fortune

Looking For Prime Value In C#

Share on :
Prime numbers according to the definition of mathematics, a number that discharged at the 1 and the number itself. Thus we can know that the first prime number in the sequence of prime numbers is the number 2. As an example consider the determination of prime numbers manually below.

5 -> divided by 2 (not finished)
divided by 3 (not finished)
divided by 4 (not finished)

6 -> divided by 2 (not finished)
divided by 3 (finished) -> remainder is zero, no need to distribute with the next number.

The Syntax :
       using System;
       using System.Collections.Generic;
       using System.Linq;
       using System.Text;
       namespace BilanganPrima
       {
       class Program
       {
       static void Main (string [] args)
       {
       Console.WriteLine ("Prime Numbers A simple program with C #. net \ n \ n");
       Console.Write ("Enter Numbers Limit Prima:");
       bool prime = true;
       int number = int.Parse (Console.ReadLine ());
       if (number> = 2)
       {
       for (int i = 2; i <= number; i + +)
       {
       for (int j = 2; j <i, j + +)
       {
       if ((i% j) == 0)
       {
       prime = false;
       break;
       }
       }
       if (prime)
       Console.WriteLine ("Numbers" + i + "is prime")
       prime = true;
       }
       }
       else
       Console.WriteLine ("No prime number can be written");
       Console.ReadLine ();
       }
       }
       }

0 comments on Looking For Prime Value In C# :

Post a Comment and Don't Spam!

Dont Spam please

 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank