Question: On Linux, create the makefile for primetest (given below) program. Test the makefile for primetest program make primetest ./primetest Code for primetest program (separated into

On Linux, create the makefile for primetest (given below) program.

Test the makefile for primetest program

make primetest

./primetest

Code for primetest program (separated into 3 source files and 2 header files):

boolean.h:

#ifndef BOOLEAN_H

#define BOOLEAN_H

#define TRUE 1

#define FALSE 0

typedef int Bool;

//function prototypes

Bool logical_and(Bool a, Bool b);

Bool logical_or(Bool a, Bool b);

Bool logical_not(Bool a);

void print_bool(Bool b);

#endif

-------------------------------------------------------------------------------------------------

boolean.c:

#include

#include "boolean.h"

Bool logical_and(Bool a, Bool b)

{

return (a&&b);

}

Bool logical_or(Bool a, Bool b)

{

return (a||b);

}

Bool logical_not(Bool a)

{

return (!a);

}

void print_bool(Bool b)

{

printf("%s ", (b ? "TRUE" : "FALSE"));

}

-------------------------------------------------------------------------------------------------

prime.h:

#ifndef PRIME_H

#define PRIME_H

Bool is_prime(int n);

#endif

-------------------------------------------------------------------------------------------------

prime.c:

#include

#include "boolean.h"

Bool is_prime(int n)

{

int divisor;

if (n <= 1)

return FALSE;

for (divisor = 2; divisor * divisor <= n; divisor++)

if (n % divisor == 0)

return FALSE;

return TRUE;

}

-------------------------------------------------------------------------------------------------

primetest.c :

#include

#include "boolean.h"

int main(void)

{

int n;

printf("Enter a number: ");

scanf("%d", &n);

if (is_prime(n))

printf("Prime ");

else

printf("Not prime ");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!