Breaking News
Loading...
Wednesday, August 22, 2012

Liệt kê n số nguyên tố đầu tiên

8/22/2012 09:53:00 PM

using System;
using System.Collections.Generic;
using System.Linqusing System.Text;
namespace Bai_Tap_13 //Liệt kê n số nguyên tố đầu tiên  
{
    class 
Program
    
{
        static 
bool KTSNT(int n)
        {
            if (
== || == || n==3)
                return 
true;
            for (
int i 2<= 2i++)
                if (
== 0)
                    return 
false;
            return 
true;
        }
        static 
void Output(ref int n)
        {
            
int dem=0;
            for (
int i 1dem != ni++)
            {
                if (
KTSNT(i) == true)
                {
                    
Console.Write("\t");
                    
dem++;
                }
            }
        }
        static 
void Main(string[] args)
        {
            
int luachonn;
            do
            {
                
Console.Write("\nNhap vao so n = ");
                
int.Parse(Console.ReadLine());
                
Console.Write("\n" " so nguyen to dau tien la: \n\n");
                
Output(ref n);
                
Console.Write("\n\nContinue? (1:Exit) => ");
                
luachon int.Parse(Console.ReadLine());
            } while (
luachon != 1);
            
Console.Write("\n");
        }
    }
}  

0 comments:

Post a Comment

 
Toggle Footer