Thursday 29 March 2012

C Programming - Sample - 3 - Use Of Subroutines

USE OF SUBROUTINES:

So far, we have used only printf function that has been provided for us by the C system. The program shown in Fig. uses a user defined function. A function defined by the user is equivalent to a subroutine in FORTRAN or subprogram in BASIC.

Figure presents a very simple program that uses a mul ( ) function. The program will print the following output.


Multiplication of 5 and 10 is 50


The mul ( 1 function multiplies the values 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.

No comments:

Post a Comment