Code:
#include <stdio.h>
#include <math.h>
int main(void)
{
double x;
printf("Enter a number: ");
scanf("%lf",&x);
printf("\n\nOriginal value: %lf",x);
printf("\nCeil: %lf",ceil(x));
printf("\nFloor: %lf",floor(x));
if (x >= 0)
printf("\nSquare root: %lf",sqrt(x));
else
printf("\nNegative Number");
printf("\nCosine: %lf\n",cos(x));
return 0;
}
A very simple example into using some of the Math functions found in math.h unfortunately gcc is complaining about the functions being undefined
/tmp/ccRRA7p2.o(.text+0x57): In function `main':
: undefined reference to `ceil'
/tmp/ccRRA7p2.o(.text+0x83): In function `main':
: undefined reference to `floor'
/tmp/ccRRA7p2.o(.text+0xc1): In function `main':
: undefined reference to `sqrt'
/tmp/ccRRA7p2.o(.text+0xfb): In function `main':
: undefined reference to `cos'
collect2: ld returned 1 exit status
The compile command if this helps
gcc math.c -o math -W -Wall -ansi
Bit puzzled to why I am getting the errors since ive included the header file.