Advertisement
vencinachev

Function Pointers - Array

Mar 21st, 2022
1,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double sum(double num1, double num2){
  4.     return num1 + num2;
  5. }
  6.  
  7. double sub(double num1, double num2){
  8.     return num1 - num2;
  9. }
  10.  
  11. double mult(double num1, double num2){
  12.     return num1 * num2;
  13. }
  14.  
  15. double div(double num1, double num2){
  16.     return num1 / num2;
  17. }
  18.  
  19. int main(){
  20.     double (*fp[4])(double,double) = { sum, sub, mult, div};
  21.     int op;
  22.     scanf("%d", &op);
  23.     printf("%.2lf\n", fp[op](10, 20));
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement