



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Based on slides from K. N. King and Dianna Xu Bryn Mawr College CS246 Programming Paradigm
#include int main() { int i = 1; int (fp) (const char , ...) = printf; fp("i == %d\n", i); (fp)("i == %d\n", i); return 0; }*
typedef struct { double x; double y; } Point; int main() { double a[5] = {0, 1, 2, 3, 4}; int b[5] = {5, 6, 7, 8, 9}; Point ps[2] = {{0.5, 0.5}, {1.5, 2.5}}; gp(a, 5, sizeof(double)); gp(b, 5, sizeof(int)); gp(ps, 2, sizeof(Point)); }
void char gp p;(void b, size_t n, size_t size){ for (p=b; p <(char)(b+(nsize)); p+=size){ switch case sizeof(double): (size) { printf("%.2f ", (double)p); case^ **break; sizeof(int): printf("%d ", (int)p); break; case printf("x sizeof(Point): = %.2f ", ((Point )p)->x); printf("y = %.2f ", ((Point )p)->y); }}^ break; printf("\n"); }
**int vs[] = {40, 10, 100, 90, 20, 25}; int comp ( const void a, const void b){ return ( (int)a - (int)b ); } int main () { qsort (vs, 6, sizeof(int), comp); }
-------^ x^ -------sin(x) 0.00000 0. 0.10000 0. 0.20000 0. 0.30000 0. 0.40000 0. 0.50000 0. -------^ x^ -------tan(x) 0.00000 0. 0.10000 0. 0.20000 0. 0.30000 0. 0.40000 0. 0.50000 0. tabulate.c /* Tabulates values of trigonometric functions / #include #include void tabulate(double double (f)(double),last, double incr);double first, 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 "\n (^) -------x (^) -------\n");cos(x)" tabulate(cos, initial, final, increment); printf("\n "\n (^) -------x (^) -------\n");sin(x)" tabulate(sin, initial, final, increment); printf("\n "\n (^) -------x (^) -------\n");tan(x)" tabulate(tan, initial, final, increment); }^ return^ 0; void tabulate(double (*f)(double), double first, { double^ last,^ double^ incr) double int i, x;num_intervals; num_intervals = ceil((last - first) / incr); for x (i= first= 0; i+ <=i num_intervals; incr; i++) { }^ printf("%10.5f^ %10.5f\n",^ x,^ (f)(x)); }