In: Computer Science
Question : Write a C++ program to find all prime numbers between 10 to 100 by using while loop. Hint: a prime number is a number that is divisible by 1 and itself. For example 3, 5, 7, 11, 13 are prime numbers because they are only divisible by 1 and themselves.
Please find below code for prime numbers and Don't forget to give a Like.
Give the input starting number and ending numbers.
Code:
#include <iostream>
using namespace std;
int main()
{
int start, last, temp,flag;
cout<<"Enter starting number: ";
cin>>start;
cout<<"Enter end number: ";
cin>>last;
if(start>last){
temp=start;
start=last;
last=temp;
}
while(start<last){
flag=0;
for(int i=2;i<=start/2;i++){
if(start%i==0){
flag=1;
break;
}
}
if(flag==0){
cout<<start<<" ";
}
++start;
}
return 0;
}
Output: