23.Function - Function Function User defined function is a...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Function Function User defined function is a code segment (block) that perform an specific action and may return a value. Function Definition: Function Definition: Return_DT F_name ( list of formal parameters) { Action_ body ; } If Return_DT is void Then: Action_body doesnt contain return statement. Else: Action_body contains return statement. Calling (invoking) Function: Calling (invoking) Function: F_name (Actual parameters); Example Example #include <iostream.h> int Max ( int Value1, int Value2) { if (Value1 > Value2) return Value1; else return Value2; } void main() { int a, b; cout<<"\nPlease Enter the values of a and b: "; cin>>a>>b; cout<<"\n the maximum one is: "<<Max(a,b)<<endl; } Function Definition Calling the function in an expression like cout<<, condition, assignment statements Example Example #include <iostream.h> int Max ( int Value1, int Value2) { if (Value1 > Value2) return Value1; else return Value2; } void main() { int a, b; cout<<"\nPlease Enter the values of a and b: "; cin>>a>>b; cout<<"\n the maximum one is: "<<Max(a,b)<<endl; } Example Example #include <iostream.h> int Sum ( int A, int B) { return...
View Full Document

This note was uploaded on 02/23/2011 for the course CHEMICAL E 2 taught by Professor Hibasaadeh during the Spring '11 term at University of Jordan.

Page1 / 18

23.Function - Function Function User defined function is a...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online