# Prime Numbers Between 1-1000

Problem:

Write a C++ program which prints all the prime numbers from 1-1000.

Prime numbers are numbers greater than 1 and which has 1 and the number itself as positive factors or divisors. It doesn't have a positive factor or divisors other than 1 and the number itself.

Let's take 5 for example:

1 and 5 (the number itself) can evenly divide 5 so they are factors of 5.

2, 3, 4 are cannot evenly divide 5 so they are not factors of 5.

Therefore, 5 is a Prime Number.

This is a program which shows the Prime Numbers from 1-1000.

/* Prime Numbers (from 1 - 1000) */ #include <iostream> using namespace std; int main(void) { int num,i,countFactors; char hang; cout << "Prime numbers (1-1000) : " << endl; for (num = 1; num <= 1000; num++) { countFactors = 0; for (i = 2; i <= num; i++) { //if a factor exists from 2 up to the number, count Factors if (num % i == 0) { countFactors++; } } //a prime number has only itself as a factor if (countFactors == 1) { cout << num << ", "; } } //to let console stay cin >> hang; return 0; }

## 8 comments

Write commentsHope this helped you!..thanks for visiting! :)

ReplyProgramming is very interesting and creative thing if you do it with love. Your blog code helps a lot to beginners to learn programming from basic to advance level. I really love this blog because I learn a lot from here and this process is still continuing.

ReplyLove from Pro Programmer

Aatka prasansa kre layak ghalo nhi btaye he Tay toh ukhar aysan tariff karths ki jano mano bhut bade ..mahapurush he

Replyhelp number between 1-1000 help tell me answer

ReplyThe prime number distribution sequence can only provide accurate results if multiple counting of equal terms is averted.

ReplyThis code is frequently ask in any examination Check Number is Prime or not in C++ is very simple and easy to write. Using for loop and if else we can write this code. Your code is very simple and easy to understand. Thanks for sharing this article.

Reply

Replyprime number distribution . (PNDS), developed by the NSI team of mathematicians2 which computes the exact count of primes numbers.