C++ console application. Програма: позьзователь вводить число, нужно вывести ростое оно или нет!
Вот я начал:
#include
#pragma warning (disable:4996)
using namespace std;
int main () {
}
Вот я начал:
#include
#pragma warning (disable:4996)
using namespace std;
int main () {
}
Решение "в лоб":
#include
#include
using namespace std;
int main () {
unsigned n;
cin >> n;
if (!cin) {
return -1;
}
int N = sqrt(n);
for (int i = 2; i <= N; ++i) {
if (n % i == 0) {
cout << "no" << endl;
return 0;
}
}
cout << "yes" << endl;
}
погуглите: Primality Test c++
#include
Вот пример кода программы (используется метод перебора делителей) на C++:
#include
using namespace std;
int main (void)
{
int number;
cout << "Enter your natural number: ";
cin >> number;
if (number > 1) {
for(int i = 2; i < number; ++i)
if (!(number % i)) {
cout << "Your number is composite." << endl;
return 0;
}
cout << "Your number is prime." << endl;
}
else if (number == 1)
cout << "You enter one." << endl;
else
cout << "You enter not natural number." << endl;
return 0;
}