0% found this document useful (0 votes)
3 views

Lab_Assignment-4

The document outlines steps to create a custom C library by defining functions in a header file with a .h extension. It includes examples of functions for various tasks such as calculating averages, generating Fibonacci sequences, displaying patterns, and converting temperatures. Additionally, it provides lab exercises to implement these functions and utilize them in programs.

Uploaded by

Ashok Garg
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)
3 views

Lab_Assignment-4

The document outlines steps to create a custom C library by defining functions in a header file with a .h extension. It includes examples of functions for various tasks such as calculating averages, generating Fibonacci sequences, displaying patterns, and converting temperatures. Additionally, it provides lab exercises to implement these functions and utilize them in programs.

Uploaded by

Ashok Garg
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/ 14

CSD101: Lab 4

Adding Functions to the Library


• Step to create your own library:
• Create a C program without main() function and save it with .h extension.
• Example: Create mylib.h library which contains a function to compute
multiplication of two integers. So the following file is saved as ‘mylib.h’
Adding Functions to the Library
• Step to create your own library:
• Create a C program without main() function and save it with .h extension.
• Example: Create mylib.h library which contains a function to compute
multiplication of two integers. So the following file is saved as ‘mylib.h’
Example use of the Library ‘mylib.h’
Example use of the Library ‘mylib.h’
Multiple function in Library mylib.h
Multiple function in Library mylib.h
Example use of the Library ‘mylib.h’
Example use of the Library ‘mylib.h’
Lab Exercise
1. Write a function that receives marks obtained by a student in 3
subjects and returns the average and percentage of these marks.
Call this function from main() and print the results in main().
2. Write a function to obtain the first 25 numbers of a Fibonacci
sequence. In a Fibonacci sequence the sum of two successive terms
gives the third term. Following are the first few terms of the
Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89…
Formula to compute Fibonacci series is:
fn = fn-1 + fn-2;
where f0=0 and f1=1
Lab Exercise
3. Write a function that displays a solid square of asterisks whose side is
specified in integer parameter side. For example, if sides is 4, the function
displays:
****
****
****
****
4. A 5-digit positive integer is entered through the keyboard, write a function
to calculate sum of digits of the 5-digit number.
5. A 5-digit positive integer is entered through the keyboard, write a
recursive function to calculate sum of digits of the 5-digit number.
Lab Exercise
6. [Separating Digits] Write a program segment that accomplish each of
the following:
a) Calculate the quotient when integer a is divided by integer b.
b) Calculate the remainder when integer a is divided by integer b.
c) Use the above functions created for part a) and b) to write a
function that inputs an integer between 1 and 32767 and prints it
as a series of digits, with two spaces between each digit.
Example: the integer 4562 should be printed as 4 5 6 2
Lab Exercise
7. Write a recursive function to obtain the first 25 numbers of a
Fibonacci sequence. In a Fibonacci sequence the sum of two successive
terms gives the third term. Following are the first few terms of the
Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89…
8. Create a Library with .h extension and add the following functions:
a) A function to check whether a number is odd or even
b) A function to check if a number is multiple of 3
c) A function to compute the largest value from three integer input
Then write a program which calls all above three functions by including
the library.
Lab Exercise
9. Implement the following functions:
a) Function to convert temperature from Celsius to Fahrenheit
b) Function to convert temperature from Fahrenheit to Celsius
c) Use the above functions to list the Fahrenheit equivalent of all
Celsius temperature from 0 to 100 degrees and Celsius equivalent
of all Fahrenheit temperatures from 32 to 212 degrees.
Formula to change from Celsius to Fahrenheit:
C = (F-32)*5/9

You might also like