Definition of the function to calculate an average : Function « Function « C / ANSI-C






Definition of the function to calculate an average

Definition of the function to calculate an average

#include <stdio.h>

float average(float x, float y) {
   return (x + y)/2.0f;
}

/* main program - execution always starts here */
void main() {

   float average(float x, float y);  /* Function prototype */

   float value1 = 1.0F;
   float value2 = 2.0F;
   float r = 0.0F;


   r = average(value1, value2);
   printf("\nThe average is: %f",  r);
}


           
       








Related examples in the same category

1.Define function to sum
2.Demonstraction of function call
3.Function call
4.Check out the int value change before and after function callCheck out the int value change before and after function call
5.Define function to multiply two int
6.Uses a function prototype to enforce strong type checking
7.Serve as a prototype within this program
8.Define function and use it: square
9.Function: Print a string in uppercase
10.A program with two functions
11.This program has three functions
12.Define function and use it
13.Return statement
14.Assign function return value to a variable
15.A simple program that demonstrates sum()
16.Define function to output char
17.Function to output square
18.Define two functions and call them in main
19.Function which returns int value
20.Define function with void return
21.Define function to calculate the ounces and cups
22.Function declaration
23.Define function to calculate the volumn
24.Function prototype: declare getnum() prior to its first use
25.Define function and return value
26.Define function with parameter and return value
27.Function call each other
28.Define two functions and make function call
29.Global and local variable inside function
30.Function prototype