Skip to content

Commit

Permalink
Prime numbers in a range using CPP
Browse files Browse the repository at this point in the history
  • Loading branch information
agrawalshreyansh authored and x0lg0n committed Oct 20, 2024
1 parent a9ce769 commit 6eef3c9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions C++/primes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//This program calculates prime numbers in a range between two numbers using C++

#include <iostream>
using namespace std ;
int main() {
int a,b ;
cin >> a ;
cin >> b ;

for (int i = a;i<=b;i++) {
int c = 0 ;
for (int j = 1; j<=i;j++) {
if (i%j == 0) {
c += 1 ;
}
}
if (c==2) {
cout << i << " ";
}
}
return 0 ;
}

0 comments on commit 6eef3c9

Please sign in to comment.