Tuesday, August 23, 2011

Prime Number Finders



// It was made with Microsoft Visual Studio C# 2010
// with the Console Application 
/* The conclution is to looking for prime numbers from 1 until the number you enter */

Here is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tampilkan_bilangan_prima
{
    class Program
    {
        static void Main(string[] args)
        {
                   
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Ini adalah program pencari bilangan prima");
            Console.WriteLine("\nKhusus untuk bilangan positif");
            Console.Write("\nSilahkan masukkan angka = ");
            string i = Console.ReadLine();
            int prima = Int32.Parse(i);

            Console.WriteLine("");
            Console.Write("Bilangan prima di antaranya adalah ");

            switch (prima)
            {
                case 1:
                    Console.WriteLine("tidak ada");
                    break;
                case 2:
                    Console.WriteLine("2");
                    break;
                case 3:
                    Console.WriteLine("2 3");
                    break;
                case 4:
                    Console.WriteLine("2 3");
                    break;
                default:
                    Console.Write("2 3 ");
                    int a = 5;
                    int b = 7;
                    for (a = 5; a <= prima; a += 6)                       
                        Console.Write(a + " ");
                    for (b = 7; b <= prima; b += 6)
                        Console.Write(b + " ");   
                    break;
            }
            Console.WriteLine("\n\n\nPress any key to continue");
            Console.ReadKey();       
        }
    }
}
Back To Home

Related Articles

0 comment:

Post a Comment