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,895 questions

51,826 answers

573 users

How to use acos() function to get the arc cosine value of N in C

2 Answers

0 votes
#include <stdio.h>     
#include <math.h>
 
int main()
{
    printf("acos(0) = %f\n", acos(0));
    printf("acos(-1) = %f\n", acos(-1));
    printf("acos(1) = %f\n", acos(1));
    printf("acos(0.5) = %f\n", acos(0.5));
  
    double ac = acos(.9);
    printf("acos(0.9) = %.6f\n", ac);
 
    return 0;
}

 
/*
run:

acos(0) = 1.570796
acos(-1) = 3.141593
acos(1) = 0.000000
acos(0.5) = 1.047198
acos(0.9) = 0.451027
 
*/

 



answered Mar 12, 2016 by avibootz
edited Dec 15, 2024 by avibootz
0 votes
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>

#pragma STDC FENV_ACCESS ON

int main(void)
{
    printf("acos(-1) = %f\n", acos(-1));
    printf("acos(0.0) = %f 2 * acos(0.0) = %f\n", acos(0), 2 * acos(0));
    printf("acos(0.5) = %f 3 * acos(0.5) = %f\n", acos(0.5), 3 * acos(0.5));
    printf("acos(1) = %f\n\n", acos(1));
   
    errno = 0; 
    feclearexcept(FE_ALL_EXCEPT);
    printf("acos(1.1) = %f\n", acos(1.1));
    if (errno == EDOM) {
        perror("    errno == EDOM");
    }
    if (fetestexcept(FE_INVALID)) {
        puts("    FE_INVALID raised");
    }
}


 
/*
run:
   
acos(-1) = 3.141593
acos(0.0) = 1.570796 2 * acos(0.0) = 3.141593
acos(0.5) = 1.047198 3 * acos(0.5) = 3.141593
acos(1) = 0.000000

acos(1.1) = nan
    errno == EDOM: Numerical argument out of domain
    FE_INVALID raised
  
*/

 



answered Mar 31, 2016 by avibootz
edited Dec 15, 2024 by avibootz

Related questions

2 answers 240 views
1 answer 155 views
1 answer 187 views
1 answer 186 views
1 answer 160 views
...