diff --git a/labtest.cpp b/labtest.cpp index 93bf6ae..0f07cba 100644 --- a/labtest.cpp +++ b/labtest.cpp @@ -1,20 +1,37 @@ -#include +#include using namespace std; -//write a user defined function to find first N prime numbers; -//the function should be named like : youname_yourid; -/* -example: +// user-defined function to find first N prime numbers +void morshedulislam_221400036(int n) { + int count = 0; -void nishat_90(int n){ -//your code here; -} -*/ + for (int num = 2; count < n; num++) { + bool isPrime = true; -int main(){ + for (int i = 2; i * i <= num; i++) { + if (num % i == 0) { + isPrime = false; + break; + } + } + if (isPrime) { + cout << num << " "; + count++; + } + } +} +int main() { int n; - cout<<"Enter the number n"<>n; + cout << "Enter the number n" << endl; + cin >> n; + + if (n <= 0) { + cout << "Please enter a positive number."; + return 0; + } + + morshedulislam_221400036(n); + return 0; }