Havvy

C Functions Compiler Error

Jul 17th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. bool isPrime(int test_num);
  5.  
  6. int main() {
  7.     printf("Hello world!\n");
  8.     if (isPrime(5)) {
  9.         printf("5 is prime.");
  10.     }
  11.     return 0;
  12. }
  13.  
  14. bool isPrime(int test_num) {
  15.     /**
  16.     Input:  test_num, an integer between two and MAXINT
  17.     Output:  true if the number is a prime number (no other natural number divides
  18.              it into an integer other than 1 and itself), false otherwise
  19.     */
  20.     bool prime = true;
  21.     int i;
  22.  
  23.     if (test_num != 2)
  24.     for(i = 3; i <= (test_num / 2); i++){
  25.         if ((test_num % i) == 0) {
  26.             prime = false;
  27.             break;
  28.         }
  29.     }
  30.     return prime;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment