Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to implement the fabs function in C

1 Answer

0 votes
#include <stdio.h>

double fabs(double x) {
    if (x == 0)
        return 0.0;

    return x < 0.0 ? -x : x;
}

int main()
{
    printf("fabs(-1.1) = %.6f\n", fabs(-1.1));
    printf("fabs(1.1) = %.6f\n", fabs(1.1));
    printf("fabs(0) = %.6f\n", fabs(0));
    printf("fabs(-0) = %.6f\n", fabs(-0));
    printf("fabs(-0.5) = %.6f\n", fabs(-0.5));

    return 0;
}




/*
run:

fabs(-1.1) = 1.100000
fabs(1.1) = 1.100000
fabs(0) = 0.000000
fabs(-0) = 0.000000
fabs(-0.5) = 0.500000

*/



 



answered Dec 25, 2022 by avibootz

Related questions

1 answer 91 views
91 views asked Jan 23, 2023 by avibootz
1 answer 57 views
57 views asked Jun 10, 2025 by avibootz
1 answer 112 views
1 answer 109 views
1 answer 88 views
88 views asked Aug 2, 2024 by avibootz
...