0
Set the boolean variable p to true if the integer n (n > 1) is a prime number, and false otherwise.
3 Respostas
+ 3
Please show your attempt and where you got stuck. No one here will do your homework for you
0
Seems to be your homework. Anyways post what you have tried
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;
}