int n, divisor = 2; cin >> n;
bool divisorFound = false;
repeat(n - 2) {
if (n % divisor == 0) {
divisorFound = true;
BlankZ ;
}
divisor++;
}
if (!divisorFound) cout << "Prime\n";
else cout << "Composite\n";
There is no need to iterate further once we have encountered a divisor of the number. What should be the command to be replaced by BlankZ?
Mention a lowercase character string as the answer.
#include <iostream>
#define repeat(n) for (int i = 0; i < n; i++)
using namespace std;
int main () {
int n, divisor = 2;
cout << "Enter a number: "; cin >> n;
bool divisorFound = false;
repeat (n - 2) {
if (n % divisor == 0) {
divisorFound = true;
}
divisor++;
}
if (!divisorFound) cout << "Entered number is Prime\n";
else cout << "Entered number is Composite\n";
return 0;
}
Comments
Leave a comment