List of all available Websheets
Viewing cpp/arrays/mastermind by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Given a positive integer from the user, <tt>n</tt>, output <tt>prime</tt> or <tt>not prime</tt> based on whether the number is actually prime. <p> A number is prime if it has no divisors other than itself and one. The first few primes are 2, 3, 5, 7, 11, … |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/control/isprime2 (author: redekopp@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; int main() { int n; cin >> n; \[ bool isPrime = true; for(int i=2; i < sqrt(n); i++) { if (n%i == 0) { // does i divide n? isPrime = false; break; } } if( isPrime ){ cout << "prime" << endl; } else { cout << "not prime" << endl; } ]\ return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "100"}, {"stdin": "17"}, {"stdin": "3"}, {"stdin": "4"}, {"stdin": "37"}, {"stdin": "39"} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.