The program shown below uses a user-defined function. A function defined by the user is equivalent to a FORTRAN subroutine or a BASIC subprogram.
It is a straightforward program that uses a mul() function.
1 /*.......... Program using Function..........*/
2 int mul(int a, int b) ; // Declaration of user-defined function
3 main()
4 {
5 int a, b, c ;
6 a= 5 ;
7 b= 10 ;
8 c= mul (a,b) ;
9 printf("Multipication of %d and %d is %d", a, b, c) ;
10 }
11
12 int mul(int x, int y)
13 {
14 int p= x*y ;
15 return(p) ;
16 }
The output of this program will be:
Multiplication of 5 and 10 is 50
The mul() function multiplies the value of x and y and the result is returned to the main() function when it is called in the statement.
c= mul(a,b) ;
The mul() has two arguments x and y that are declared as integers. The values of a and b are passed on to x and y respectively when the function mul() is called.
User-defined functions will be discussed in detail in the function topic.
----------------------------------------------------------------------------------------------------------------------------
Explore our website for valuable C programming resources and enhance your coding skills today!.
Learn C programming language from basic to advanced here (Click here or on the image)
Stay Strong, keep learning, and keep growing.