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
Prime Numbers in C
Shobana J
Jul 15, 2016
18.2
k
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, I am going to explain how to check a number for whether it is a prime number or not.
PRIME.zip
Introduction
In this article, I am explaining how to check and print a prime number.
Software Requirements
Turbo C++ or C.
Programming
#include < stdio.h >
int
main()
{
int
n, i = 3, count, c;
printf(
"Enter the number of prime numbers required\n"
);
scanf(
"%d"
, & n);
if
(n >= 1)
{
printf(
"First %d prime numbers are :\n"
, n);
printf(
"2\n"
);
}
for
(count = 2; count <= n;)
{
for
(c = 2; c <= i - 1; c++)
{
if
(i % c == 0)
break
;
}
if
(c == i)
{
printf(
"%d\n"
, i);
count++;
}
i++;
}
return
0;
}
Explanation
In the above program, the prime number can be displayed in simple manner.
Output
Conclusion
Thus, the program can be displayed and executed successfully, in a simple manner.
Prime Number
C
Next Recommended Reading
Armstrong Number In C