Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Prime Numbers in C
WhatsApp
Shobana J
8y
18.3
k
0
2
25
Blog
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.
C
Prime Number
Up Next
Armstrong Number In C
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found