Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- #include "Header.h"
- int main() {
- double dFrom, dTo, y;
- int i, j, iNumber;
- char sAnswer[256];
- char sAgree[] = "Yes";
- struct Func {
- double (*pFunc)(double);
- const char *fname;
- } funcs[] = { {sin, "sin(x)"}, {cos, "cos(x)"}, {tan, "tg(x)"}, {sinh, "sh(x)"},
- {cosh, "ch(x)"}, {SinPlusCos, "sin(x)+cos(x)"} };
- double res[3] = { 0, 0, 0 };
- for (i = 0; i < 6; i++) {
- printf("%d: %s\n", i, funcs[i].fname);
- }
- for (;;) {
- printf("Choose the function: \n");
- scanf_s("%d", &iNumber);
- if ((iNumber >= 0) & (iNumber < (sizeof(funcs) / sizeof(struct Func)))) {
- printf("From: \n");
- scanf_s("%lf", &dFrom);
- printf("To: \n");
- scanf_s("%lf", &dTo);
- y = NumericIntegral(funcs[iNumber].pFunc, dFrom, dTo, 1e-6);
- printf("Integral_of_%s from: %.3f to: %.3f = %lf \n", funcs[iNumber].fname, dFrom, dTo, y);
- printf("Do you want to continue? \n");
- for (;;) {
- fgets(sAnswer, sizeof(sAnswer), stdin);
- if (sAnswer[0] != '\n')break;
- }
- if (tolower(sAnswer[0]) == tolower(sAgree[0]))
- continue;
- else break;
- }
- else printf("We haven\'t added such a function yet. Please, try again. ");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement