#include<stdio.h>#include<math.h>/* Compile: cc -g -ansi -pedantic -Wall -O2 -o function function.c -lm *//* Run: ./function *//* Prototyping: *//* When compiling with -Wall flag, prototyping is mandatory if the functions are placed after main(). *//* It is always good practice to prototype your functions. */floatsquare(doublef);
floatsquareroot(doublef);
intmain()
{
floatf1, f2;
f1 = square(3);
f2 = squareroot(10);
printf("The square of 3 = %f\n", f1);
printf("The square root of 10 = %f\n", f2);
return 0;
}
floatsquare(doublef)
{
return pow(f, 2);
}
floatsquareroot(doublef)
{
return sqrt(f);
}
With functions in a separate file, myfunctions.h, included with the #include statement:
(Note that we do not have to prototype the functions, but we do, simply because it is good practice;-)