 # C++ Programming Code Examples

## C++ > Mathematics Code Examples

### Print Prime Numbers

``` Print Prime Numbers To print all prime number between the particular range in C++ programming, check division from 2 to one less than that number (i.e., n-1), if the number is divided to any number from 2 to one less than that number then that number will not be prime. Otherwise, that number will be prime number as shown here in the following program. To print prime number between range for example, to print prime number between 3 to 29, here 3 is the starting number and 29 is the ending number, so following C++ program ask to the user to enter the starting and ending number to find and print all the prime number exists between the given range (here we are including the starting and ending number also if they are prime): #include<iostream.h> #include<conio.h> void main() { clrscr(); int start, end, i, j, count=0; // to print all the prime number between any range // enter the two number (starting and ending) cout<<"Enter starting number : "; cin>>start; cout<<"Enter ending number : "; cin>>end; cout<<"Prime Number Between "<<start<<" and "<<end<<" is :\n"; for(i=start; i<=end; i++) { count=0; for(j=2; j<i; j++) { if(i%j==0) { count++; break; } } if(count==0) { cout<<i<<" "; } } getch(); } ``` 