How to Make Series of Prime Numbers in C++

How to Make Series of Prime Numbers in C++

Starting and understanding C++ is not much difficult but it needs good concentration to understand the logic of c++. One have to practice more and more to find the way and the logic of thinking in c++. After studying some basic concepts and topics in c++ such as: Finding IDE for working on, Understanding the Structure of the C++, Libraries, Data-Types, Variables, Loops and etc… you can write and run basic programs. One of the programs which is often used to understand the mentioned concept better is to;

Read : [button link=”” target=”blank” color=”blue” icon=”none” style=”normal” size=”medium”]Arrays in c++[/button]      [button link=”” target=”blank” color=”blue” icon=”none” style=”gloss” size=”medium”]Struct in C++[/button]

Write a program that should print or make series of the Prime Numbers :

First we have to that actually what is a prime number and its series?

Ans: A number that is divisible only by  itself and 1.

There are different ways to write a program that prints the prime number series. I am going to describe and explain a simple way to write the mentioned program. You have to about Loops, Variables and Basic Concept of C++.

  1. Create new c++ file inside your IDE, include the library <iostream>, place std namespace and main function.
  2. Write codes to ask  Prime Number series.
  3. Put a loop like for to repeat the process of finding the Prime Number  untill the it reaches the length entered by the user.

[textmarker color=”1FC240″ type=”background color”]

Algorithm to check whether a number is prime number or not

Let, N be a positive number.

For every number i, between 2 to N/2(2<= i <= N/2) check whether i divides N completely(check If i is a factor of N). if (N % i == 0), then N cannot be a Prime number.

If none of the number between 2 to N/2 divides N completely then N is a prime number.


Check out the program below:


The OutPut:

Find prime number

Feel free to share your comments and ask questions!



Raza Bayani

Raza Bayani studies BCE (Bachelor in Computer Engineering) in Poly-technical University of Kabul. He is the CEO of CODEJOW group, a web designer, coder and recently a blogger. Raza thinks, he can help others and also boost-up his own programming skills being on

Related Posts