0

Set the boolean variable p to true if the integer n (n > 1) is a prime number, and false otherwise.

19th Apr 2021, 5:58 PM
Nikita Volkov
Nikita Volkov - avatar
3 odpowiedzi
+ 3
Please show your attempt and where you got stuck. No one here will do your homework for you
19th Apr 2021, 5:59 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
0
Seems to be your homework. Anyways post what you have tried
19th Apr 2021, 6:05 PM
Atul [Inactive]
0
I want to add a while loop here. #include "locale.h" #include <iostream> #include <stdio.h> #include <conio.h> #include <tchar.h> #include <string> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { setlocale(LC_ALL, "Russian"); int n; cout << "Введите целое число n " << endl; printf("n = "); scanf_s("%d", &n); bool p = true; for (int i = 2; i < n; i++) { if (n % i == 0) { p = false; break; } } if (p) printf("%d - false ", n); else printf("%d - true ", n); _getch(); return 0; }
20th Apr 2021, 7:51 PM
Nikita Volkov
Nikita Volkov - avatar