-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabulate.c
48 lines (35 loc) · 1.09 KB
/
tabulate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Tabulates values of trigonometric functions */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void tabulate(double (*f)(double), double first, double last, double incr);
int main(void)
{
double final, increment, initial;
printf("Enter initial value: ");
scanf("%lf", &initial);
printf("Enter final value: ");
scanf("%lf", &final);
printf("Enter increment: ");
scanf("%lf", &increment);
printf("\n x cos(x)\n"
" -------- --------\n");
tabulate(cos, initial, final, increment);
printf("\n x sin(x)\n"
" -------- --------\n");
tabulate(sin, initial, final, increment);
printf("\n x tan(x)\n"
" -------- --------\n");
tabulate(tan, initial, final, increment);
return 0;
}
void tabulate(double (*f)(double), double first, double last, double incr)
{
double x;
int i, num_intervals;
num_intervals = ceil((last - first) / incr);
for (i = 0; i <= num_intervals; i++) {
x = first + i * incr;
printf("%10.5f %10.5f\n", x, (*f)(x));
}
}