Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- bool isPrime(int test_num);
- int main() {
- printf("Hello world!\n");
- if (isPrime(5)) {
- printf("5 is prime.");
- }
- return 0;
- }
- bool isPrime(int test_num) {
- /**
- Input: test_num, an integer between two and MAXINT
- Output: true if the number is a prime number (no other natural number divides
- it into an integer other than 1 and itself), false otherwise
- */
- bool prime = true;
- int i;
- if (test_num != 2)
- for(i = 3; i <= (test_num / 2); i++){
- if ((test_num % i) == 0) {
- prime = false;
- break;
- }
- }
- return prime;
- }
Advertisement
Add Comment
Please, Sign In to add comment