Simple Example OF Subroutines In C Programming

Written by

kaleidoscope + subroutines In C Programming

CODE:

//include the required libraries here
void main()
{
int input01, input02, result;

//give some inputs, but you can make it this C program interactive
input01 = 25;
input02 = 10;

result = multiply(input01,input02);    //subroutine call

printf(“Multiplication of %d and %d is %d”,input01,input02,result);
}

/* subroutine definition block */
int multiply(int x, int y)
{
return x*y;
}

OUTPUT:

Multiplication of 25 and 10 is 250

When execution starts and encounters the statement ‘result = multiply(input01,input02);‘, execution goes to the function or subroutine call. We can visualise it as follows:

VISUALISATION:

int multiply(25, 10)
{
return 25*10;   //computes and returns 250
}

Therefore, multiply() returns its result which is stored into the variable ‘result‘. After the value is returned, execution goes back to main and proceeds to the next statement.

star Other Simple C Programming Tutorials:
=> Random Numbers in C programming
=> It’s Too Easy To Make This Simple, But Worse, Logical Error In Programming
=> Format Specifiers Used In C Programming
=> A simple Interactive C Program Using Scanf Function



Posted in: World Of Programming

  No Comment yet - Be the first to respond to " Simple Example OF Subroutines In C Programming "!

Use The Form Below To Leave Your Comment(s):

Feel free to use these tags in your comments: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>