Advertisement
JuliaPopadowska

zad 3/2 PN - tablica funkcji

Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "math.h"
  3.  
  4. double sin1(double x, bool &ok)
  5. {
  6.     ok = true;
  7.     return sin(x);
  8. }
  9.  
  10. double tg1(double x, bool &ok)
  11. {
  12.     if (cos(x) == 0) ok = false;
  13.     else ok = true;
  14.     return sin(x) / cos(x);
  15. }
  16.  
  17. double arcsinx(double x, bool &ok)
  18. {
  19.     if (x>-1 && x<1) ok = false;
  20.     else ok = true;
  21.     return asin(x);
  22. }
  23.  
  24. double pierw(double x, bool &ok)
  25. {
  26.     if (x < 0) ok=false;
  27.     else ok = true;
  28.     return sqrt(x);
  29. }
  30.  
  31. double logn(double x, bool &ok)
  32. {
  33.     if (x <= 0) ok = false;
  34.     else ok = true;
  35.     return log(x);
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41.     char pol;
  42.     double x,wynik;
  43.     bool ok;
  44.     int opcja;
  45.     double(*tab[])(double, bool &) = { sin1,tg1,arcsinx,pierw,logn };
  46.     while ()
  47.     {
  48.     printf_s("Podaj polecenie: ");
  49.     scanf_s("%c", &pol,1);
  50.         if (pol == 'n')
  51.         {
  52.             printf_s("Podaj liczbe: ");
  53.             scanf_s("%lf", &x);
  54.         }
  55.         if (pol == 'f')
  56.         {
  57.             printf_s("Podaj opcje: ");
  58.             scanf_s("%d", &opcja);
  59.             wynik = tab[opcja](x, ok);
  60.             if (ok)
  61.                 printf_s("%lf", wynik);
  62.             else printf_s("bledny argument");
  63.         }
  64.         if (pol == 'q')
  65.         {
  66.             return 0;
  67.         }
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement