PDF PF Lab Report
PDF PF Lab Report
Write a C function 'int test_prime(int);' that takes in a positive number as input and returns
true (1) if the input number is prime or false (0) if the input is not prime. Then using this
function, write a C program that takes a number (N) as input from the user and prints out
the first N prime numbers.
In-Lab Task 2:
(a) Write a C program that asks user to input a value for 𝜃 in degrees .It should
then calculate the value of the mathematical function 𝐲 and print its value
on screen. Write separate functions to implement 𝑓1 (𝜃) 𝑎𝑛𝑑 𝑓2 (𝜃) .
Hint: include the ‘math.h’ library and use the following functions. Remember
that these functions expect inputs to be in Radians.
double sin(double x);
double cos(double x);
𝑦 = 𝑓1 (𝜃) + 𝑓2 (𝜃)
𝑓1 (𝜃) = (cos 𝜃 /2 ) ^2 , 𝑓2 (𝜃) = − (sin 𝜃 /2 ) 2
(b) Modify the above program to calculate the value of 𝑦.
(c) Hint: include the ‘math.h’ library and use the following function:
double sqrt(double x);
𝑦 = 𝑓1 (𝜃) + 𝑓2 (𝜃) + 𝑓3 (𝜃)
𝑓1 (𝜃) = (cos 𝜃 /2 ) ^2 ,
𝑓2 (𝜃) = 0.5√( 1 + cos 2𝜃)/ 2 ,
𝑓3 (𝜃) = 1 /2
Output:
Post Lab Task:
Write a C program that takes two floating type inputs from the user and
calculates their average, individual factorials, and a function 𝑓(𝑥, 𝑦) = √𝑥 2 + 𝑦 2.
Use separate C functions to compute the average, factorial and the function ‘f’.
The program should print the results in the main function.
Output:
Summary: