5.4.Function Definition
Function definition is a function body that noted what function will do.
Syntax 1:
Return_type Function_name (para 1, para 2,… , para n) { statement 1; statement 2; ... statement n; return value; }
Syntax 2:
Non Return type function_name(para 1, para 2,… , para n) { statement 1; statement 2; ... statement n; }
Example 1:
float sum(float v1, float v2, float v3) { float s; s=v1+v2+v3; return s; }
Example 2:
void sum1(float v1, float v2, float v3) { float s1; s1=v1+v2+v3; cout<<“Sum of three values: “<<s1; }
Example 3:
int maximum(int v1,v2,v3) { int max; if(v1>v2&&v1>v3) max=v1; else if(v2>v1&&v2>v3) max=v2; else max=v3; return max; }
Example 4:
void maximum(int v1,v2,v3) { if(v1>v2&&v1>v3) cout<<"Maximum is: "<<v1; else if(v2>v1&&v2>v3) cout<<"Maximum is: "<<v2; else cout<<"Maximum is: "<<v3; }