using System
;
using System
.
Collections
.
Generic
;
using System
.
Linq
;
using 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
==
1
||
n
==
2
||
n
==
3
)
return
true
;
for (
int i
=
2
;
i
<=
n
/
2
;
i
++)
if (
n
%
i
==
0
)
return
false
;
return
true
;
}
static
void Output
(
ref int n
)
{
int dem
=
0
;
for (
int i
=
1
;
dem
!=
n
;
i
++)
{
if (
KTSNT
(
i
) ==
true
)
{
Console
.
Write
(
i
+
"\t"
);
dem
++;
}
}
}
static
void Main
(
string
[]
args
)
{
int luachon
,
n
;
do
{
Console
.
Write
(
"\nNhap vao so n = "
);
n
=
int
.
Parse
(
Console
.
ReadLine
());
Console
.
Write
(
"\n"
+
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