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

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,943 questions

55,787 answers

573 users

How to use math functions in C

1 Answer

0 votes
// #include <math.h> gives you access to:
// sqrt, cbrt
// log, log10, exp
// fabs, floor, ceil, pow
// M_PI, M_E (if supported)

#include <stdio.h>
#include <math.h>

int main() {
    double x = 9.0;

    printf("sqrt(x) = %f\n", sqrt(x));
    printf("log(x)  = %f\n", log(x));     // natural log
    printf("exp(1)  = %f\n", exp(1));     // e^1
    printf("fabs(-3.5) = %f\n", fabs(-3.5));
    printf("floor(3.7) = %f\n", floor(3.7));
    printf("ceil(3.2)  = %f\n", ceil(3.2));
    printf("pow(2, 8)  = %f\n", pow(2, 8));

    return 0;
}


/*
run:

sqrt(x) = 3.000000
log(x)  = 2.197225
exp(1)  = 2.718282
fabs(-3.5) = 3.500000
floor(3.7) = 3.000000
ceil(3.2)  = 4.000000
pow(2, 8)  = 256.000000

*/


 



answered Apr 30 by avibootz
edited Apr 30 by avibootz
...