Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is a dummy exercise to test your level on programming.
- Don't consider it to be a "deal breaker". This is not an exercise
- you can "fail" or "pass". The idea is just to see where you are
- standing regarding programming knowledge.
- Please be honest. Try to answer it without googling for the
- solution online. Of course you can Google all you want about
- how to write an if statement, a for, or whatever you want.
- Again. Be honest, it's almost anonymous (I'm the only one that will
- see your answers) and it's for your best interests.
- """
- ### Assignment ###
- #
- # Your assignment is to implement the
- # following function: `find_next_prime`.
- # As the name states, given the number `n` the
- # function should return the next closest prime.
- #
- # Examples:
- # * `find_next_prime(6)` should return 7.
- # * `find_next_prime(10)` should return 11.
- # * `find_next_prime(11)` should return 13.
- #
- # You can use whatever you want (data structures,
- # language features, etc).
- #
- # Unit tests would be a plus. Actually, just knowing what
- # they are would be a plus :)
- #
- ### End Assignment ###
- //Realize that I have no experience with python so I'm doing this in c++. My apologies if this is not what you wanted.
- // Dewey McPherson
- bool isPrime(n)
- {
- int i;
- for (i=2; i<number; i++)
- {
- if (number % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- int find_next_prime(n)
- {
- int prime = 0;
- while( prime == 0)
- {
- if(isPrime(n))
- {
- return n;
- }
- n++;
- }
- }
- int main()
- {
- int n;
- printf("Please enter your number: ");
- scanf("%i",&n);
- n = find_next_prime(n);
- printf(" \n The next prime is %i ", n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement