Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6. #include "Header.h"
  7.  
  8. int main() {
  9.     double dFrom, dTo, y;
  10.     int i, j, iNumber;
  11.     char sAnswer[256];
  12.     char sAgree[] = "Yes";  
  13.     struct Func {
  14.         double (*pFunc)(double);
  15.         const char *fname;
  16.     } funcs[] = { {sin, "sin(x)"}, {cos, "cos(x)"}, {tan, "tg(x)"}, {sinh, "sh(x)"},
  17.     {cosh, "ch(x)"}, {SinPlusCos, "sin(x)+cos(x)"} };
  18.     double res[3] = { 0, 0, 0 };
  19.     for (i = 0; i < 6; i++) {
  20.         printf("%d: %s\n", i, funcs[i].fname);
  21.     }
  22.     for (;;) {
  23.         printf("Choose the function: \n");
  24.         scanf_s("%d", &iNumber);
  25.         if ((iNumber >= 0) & (iNumber < (sizeof(funcs) / sizeof(struct Func)))) {
  26.             printf("From: \n");
  27.             scanf_s("%lf", &dFrom);
  28.             printf("To: \n");
  29.             scanf_s("%lf", &dTo);
  30.             y = NumericIntegral(funcs[iNumber].pFunc, dFrom, dTo, 1e-6);
  31.             printf("Integral_of_%s from: %.3f to: %.3f = %lf \n", funcs[iNumber].fname, dFrom, dTo, y);
  32.             printf("Do you want to continue? \n");
  33.             for (;;) {
  34.                 fgets(sAnswer, sizeof(sAnswer), stdin);
  35.                 if (sAnswer[0] != '\n')break;
  36.             }
  37.             if (tolower(sAnswer[0]) == tolower(sAgree[0]))
  38.                 continue;
  39.             else break;
  40.         }
  41.         else printf("We haven\'t added such a function yet. Please, try again. ");
  42.     }
  43.     return 0;
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement