fork download
  1. #include <iostream>
  2. //#include <math.h>
  3. //#include <iomanip>
  4. //#include <stdio.h>
  5. using namespace std;
  6.  
  7. double f1(double x)
  8. {
  9. return(2*x);
  10. }
  11.  
  12. double f2(double x)
  13. {
  14. return(x*x);
  15. }
  16.  
  17. double compute(double f(double x), double i)
  18. {
  19. double answer;
  20. answer = f(i);
  21. return (answer);
  22. }
  23.  
  24. int main()
  25. {
  26. double input, ans;
  27. int function;
  28.  
  29. double (*gset[])(double)={f1,f2};
  30.  
  31. cout << "Input Please: ";
  32. cin >> input;
  33. cout << "Function Please: ";
  34. cin >> function;
  35.  
  36. ans = compute(gset[function-1], input);
  37. cout << ans;
  38. }
Success #stdin #stdout 0.01s 2860KB
stdin
5
2
stdout
Input Please: Function Please: 25