C++ Program to Find Prime number between 1 to 100

Finding Prime number between 1 to 100

A prime number is an positive integer that has no integer factors except one and itself or can only be exactly divided by the integers 1 and itself without leaving a remainder.
For example 73 is prime, because it can only be divided by 1 and 73.So prime number has two factor one is 1 another is number itself is called prime number.

The number 1 is neither prime nor composite. Algorithm of Finding Prime number

• In that C++ program simple we will include header file,then we declared i,j and count.initialize the variable count with 0 for counting the factor of the number.
• The first loop for iteration of the number from 1 to 100 and nested loop for checking the prime number.
• The condition for count factor of the number, if factor is 2 that number is prime.  C++ Code to Prime number between 1 to 100

//Cpp Code to find prime number between 1 to 100
#include <iostream>
using namespace std;
///Main Function
int main()
{
int i,j,count=0;

//Print prime number between 1 to 100
cout<<"print prime number between 1 to 100\n";

//For loop for printing values between 1 to 100
for(i=2;i<=100;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
count++;

}
if(count==2)
cout<<" "<<i;
count=0;
}
return 0;
}
Output:
Prime number between 1 to 100
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97