thevals

lab6

Dec 9th, 2021 (edited)
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. double f1(int);
  4. int f2(void);
  5. int f3(void);
  6. int main() {
  7.     int(*ptr)(void);
  8.     ptr = f2;
  9.     ptr();
  10.     ptr = f3;
  11.     ptr();
  12.  
  13.     int(*ptMas[])(void) = { f2, f3 };
  14.     ptMas[0]();
  15.     ptMas[1]();
  16.     int mas[3] = { (int)f1, (int)f2, (int)f3 };
  17.     double (*pt1)(int);
  18.     pt1 = (double(*)())mas[0];
  19.     double m = pt1(0);
  20.     printf("\nm= %f", m);
  21.     for (int i = 1; i < 3; i++) {
  22.         ptr = (int(*)())mas[i];
  23.         ptr();
  24.     }
  25.     printf("\n\n");
  26.     double(*ppf)(double);
  27.     ppf = sin;
  28.     printf("sin(0.5) = %f\n", ppf(0.5));
  29.     ppf = cos;
  30.     printf("cos(0.5) = %f\n", ppf(0.5));
  31.  
  32.     return 0;
  33. }
  34. double f1(int a) {
  35.     printf("\ndouble f1(int a)");
  36.     double b = a;
  37.     if (a == 0) return b + 1.0;
  38.     else return 1.0 / b;
  39. }
  40. int f2()
  41. {
  42.     printf("\nint f2(void)");
  43.     return 200;
  44. }
  45. int f3() {
  46.     printf("\nint f3(void)");
  47.     return 300;
  48. }
Add Comment
Please, Sign In to add comment