Programming - Languages - Lecture-17 & 18 - Fall-2022
Programming - Languages - Lecture-17 & 18 - Fall-2022
Lecture-17&18
Corse Title: Programming Language
Course Code: EL-255
Course Teachers: Dr. Sadia Muniza Faraz
Semester: Fall-2022
Offered to: S.E. (Electronic Engineering)
Chapter-5
Functions
1
12/23/2022
Example
#include <stdio.h>
int add(int,int); Function Declaration
main()
{
int a=4,b=6,c; Function Call
c = add(a,b);
printf(“value of c = %d”,c);
}
int add( int x, int y)
{ Function Definition
int sum;
sum=x+y;
return(sum);
}
Function Definition:
• Function definition contains the actual code of
execution task. In function definition we write
code whatever we want to perform by using
function.
return-type function-name (parameters)
{
declarations
statements
return value;
}
2
12/23/2022
Exercise
• Write a program which takes radius of a
sphere as input and prints its surface area and
volume using functions
• Make separate functions for area and volume.
3
12/23/2022
Exercise
Write a program which takes temperature and its
units input and prints it in centigrade, Fahrenheit
and Kelvin (use switch case with functions)
9
f c 32
5
5
c f 32
9
k c 273
4
12/23/2022
Exercise
• Write a program to evaluate sin(x) series upto
6 terms, for a value of x
x3 x5 x7
sin( x) x ...
3! 5! 7!
THE END
10