From 6eef3c99e97b1b14daa5cdf08cc73a8ade25c385 Mon Sep 17 00:00:00 2001 From: shreyansh Date: Sun, 20 Oct 2024 02:51:06 +0530 Subject: [PATCH] Prime numbers in a range using CPP --- C++/primes.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 C++/primes.cpp diff --git a/C++/primes.cpp b/C++/primes.cpp new file mode 100644 index 0000000..d53e901 --- /dev/null +++ b/C++/primes.cpp @@ -0,0 +1,22 @@ +//This program calculates prime numbers in a range between two numbers using C++ + +#include +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 ; +}