Simple Example OF Subroutines In C Programming

Want To Be Part Of my 7-Week's Lessons To Help You Propel Your Objectives & Eradicate Frustrations In Your Life?
Subscribe FREELY Right Now - click here!

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.

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

Speak Your Mind

*