0% found this document useful (0 votes)
41 views6 pages

PDF PF Lab Report

This lab report contains solutions to three programming tasks. For the first task, a function was created to check if a number is prime and a program that finds the first N prime numbers was written. The second task involved writing a program to calculate a mathematical function based on the value of theta input by the user. Separate functions were used to calculate parts of the function. The final task took two floating point numbers as input and used separate functions to calculate the average, factorials, and value of another function of the two numbers. Results were displayed in the main function.

Uploaded by

nayyabkanwal2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views6 pages

PDF PF Lab Report

This lab report contains solutions to three programming tasks. For the first task, a function was created to check if a number is prime and a program that finds the first N prime numbers was written. The second task involved writing a program to calculate a mathematical function based on the value of theta input by the user. Separate functions were used to calculate parts of the function. The final task took two floating point numbers as input and used separate functions to calculate the average, factorials, and value of another function of the two numbers. Results were displayed in the main function.

Uploaded by

nayyabkanwal2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab Report #05

Name: Nayyab Kanwal


Reg No: CIIT/FA-23-BCE-088/ISB
Date: 28-11-2023
Instructor Name: Sir Babar Mansoor
In-Lab Task 1:

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:

Following are the problems that I solved in this report:


In lab task:
In this program we take input from user in main function and display the result by using
other function .In 2nd function we apply the logic of checking prime numbers by using for
loop .A number which gives remainder zero when divided by all number, except 1 and number
itself is a prime number.
In lab task 2:
In this program user take input theta in main function and display result by using other
function. In 2nd function we calculate f1, f2, f3 from the given formulas. At last we calculate
the sum of these functions.
Post lab :
In this program user take input 2 floating number and using o three functions except main
function .One function calculate the average of number ,2nd function calculate the factorial of
2 number and 3rd function calculate f(x,y).After calculating the result will display in main
function.

You might also like