W12-LibraryFunctions

W12-LibraryFunctions - Library Functions 10/17/05 1...

Info iconThis 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 + =
Background image of page 1

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

View Full DocumentRight Arrow Icon
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);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/28/2009 for the course CS 151 taught by Professor Staff during the Spring '08 term at Oregon State.

Page1 / 7

W12-LibraryFunctions - Library Functions 10/17/05 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online