반응형
// 3000이하의 소수를 구하는 한글 씨샾코드 // 한국인에게 궁극적인 가독성이란 한글로 된 한국어 변수명을 쓰는 것이 아닐래나. // 인텔리센스가 한국어에게 친절한 것 같지는 않네.
using System;
using System.Collections.Generic;
namespace 소수구하기
{
class Program
{
private static LinkedList<decimal> 전체소수;
private static bool 참 = true;
private static bool 거짓 = false;
static void Main(string[] args)
{
decimal[] 소수처음몇개 = { 2, 3, 5, 7 };
전체소수 = new LinkedList<decimal>(소수처음몇개);
decimal 소수후보;
소수후보 = 9;
while (소수후보 < 3000) {
if (소수냐(소수후보)) 전체소수.AddLast(소수후보);
소수후보 +=2;
}
보여줘(전체소수);
}
private static void 보여줘(LinkedList<decimal> 수들) {
Console.WriteLine();
foreach (decimal 한개씩 in 수들) {
Console.Write(한개씩 + " ");
}
}
private static bool 소수냐(decimal 검사할수) {
foreach (decimal 소수 in 전체소수) {
if (소수 * 소수 > 검사할수) break;
if (검사할수 % 소수 == 0) return 거짓;
}
return 참;
}
}
}
728x90
'프로그래밍 > C#' 카테고리의 다른 글
[C#] 페졸드책연습중에 한글로 장난 (0) | 2008.11.06 |
---|---|
C# 예제 : 클래스 (0) | 2007.04.07 |