The copiler fails when I use the abs () function in this program. why ?

0 votes
asked Apr 29 by Dácio Melo (170 points)
#include <stdio.h>
int main(){
    int a=-1;
    printf("abs(a) = %i",abs(a));
    return 0;
}

2 Answers

+1 vote
answered Apr 29 by LiOS (5,120 points)
selected May 1 by Dácio Melo
 
Best answer
The code works but it will complain about implicit declaration of abs() function because the system header file for it hasn't been called. abs() is found in the stdlib.h header file.

Working code with no complaints:

#include <stdio.h>
#include <stdlib.h>

int main()
{

    int a=-1;
    printf("abs(a) = %i",abs(a));

    return 0;
}
0 votes
answered Apr 30 by kshethra reddy (140 points)
abs function is found in math.h header file.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...