Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

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

2 Answers

+1 vote
answered Apr 29, 2020 by LiOS (6,160 points)
selected May 1, 2020 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, 2020 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.
...