ahmed0saber

Prime numbers between 2 numbers in C++

Dec 24th, 2020 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n1,n2, constant=1;
  6. cout<<" please enter the first number"<<endl;
  7. cin>>n1;
  8. cout<<" please enter the seconde number"<<endl;
  9. cin>>n2;
  10. cout<<"********************"<<endl;
  11. for(int i=n1 ; i<=n2 ; i++)
  12. {
  13. for(int x=2 ; x<i ; x++)
  14. {
  15. if ( i % x == 0){
  16. constant++;}
  17. }
  18. if ( constant ==1){
  19. cout<<i<<endl;}
  20. constant=1;
  21. }
  22. }
Add Comment
Please, Sign In to add comment