//global variable x, can be accessed from anywhere
float x = 4.5;
//inform the compiler, that a function that is defined later, but it exists in the code, and to use it before it's defined, we need to know how it looks like:
float f(float a);
//I need to specify what my main function returns, typically "int"
int main()
{
//local variable for saving the result in:
float y;
//multiply x, with 2, and save the result in x:
x*=2.0;
//run the function:
y=f(x);
//show the result:
printf("\n%f%f",x,y);
//return a value to let the OS know how the program ended (0 is success)
return 0;
}
//define the function
float f (float a)
{
//whatever a is provided, add 1.3 to it before doing anything else
a+=1.3;
//subtract 4.5 from the global variable, before doing anything else:
x-=4.5;
//return the sum of a and x, as the result of this function.
return(a+x);
}
the math here is:
x = 4.5
x = (x * 2) = 9
a = (x = 9) = 9
a = (a + 1.3) = 10.3
x = (x - 4.5) = 4.5
y = a + x = (4.5 + 10.3) = 14.8