{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

W12-LibraryFunctions

W12-LibraryFunctions - Library Functions 1 Function...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
10/17/05 1 Library Functions 10/17/05 2 Function Libraries <stdio.h> - printf(), fprintf(), scanf(), fscanf(), fopen(), putchar(), getchar(), etc. <math.h> - pow(), sqrt(), fabs(), etc. <ctype.h> - toupper(), tolower(), isalpha(), isdigit(), etc. <stdlib.h> - rand(), srand(), exit(), etc. <time.h> - time(), clock(), etc. 10/17/05 3 pow(base, exp) example. value = pow((1+i), -n); /* i.e. value = (1+i) -n */ sqrt(value) example. root = sqrt(x*x+y*y); /* i.e. */ fabs(value) example; err = fabs((x-xe)/x); /* i.e. err=|(x-xe)/x| */ <math.h> 2 2 y x root + =
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10/17/05 4 <stdlib.h> exit(val) example if (fp == NULL) exit(1); /* e.g. quit program if error in fopen */ rand(void) example for (i=0; i < 100; ++i) /* 100 random numbers*/ printf("%d ", rand()); srand(value) example srand(100); /* sets beginning of sequence */ 10/17/05 5 <time.h> time(NULL) example int secs; secs = time(NULL); /* seconds since 1/1/70 */ clock() example int msec; msec = clock(); /* msec since computer started */ 10/17/05 6 Math Functions How accurate is 22/7 for pi? #include <stdio.h> #include <math.h> int main( void ) { double pi, est, error; pi = 2 * asin(1); /* use arcsin to get value for pi */ est = ( double )22/7; /* calc the estimate */ error = fabs(est – pi)/pi; /* find the error */ printf("pi = %.15f\n", pi); /* print results */ printf("est = %.15f\n", est); printf("error = %.5f", error * 100); return 0; }
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern