TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Twin Prime Numbers Within A Range In C#
Soumalya Das
Aug 27
2016
Code
4.4
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
namespace
Consolepractice {
class
Program {
public
static
void
Main(
string
[] args) {
Program pg =
new
Program();
for
(
int
i = 2; i <= 200; i++) {
if
(pg.checkprime(i) ==
true
&& pg.checkprime(i + 2) ==
true
) {
Console.WriteLine(i +
","
+ (i + 2));
}
}
Console.ReadKey();
}
public
bool
checkprime(
int
n) {
int
flag = 0;
for
(
int
i = 2; i <= n / 2; i++) {
if
(n % i == 0) {
flag = 1;
break
;
}
}
if
(flag == 0) {
return
true
;
}
else
{
return
false
;
}
}
}
}
Twin Prime Numbers
C#