fork download
  1.  
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. const int NN=10;
  6. double a,b;
  7. int counter=0;
  8.  
  9. typedef void (*oper)(void);
  10. struct argList{double* refVar; double val;};
  11.  
  12. argList* data;
  13.  
  14. void meanArifGeom(void) {
  15. double x=0.5*(a+b);
  16. double y=sqrt(a*b);
  17. a=x;b=y;
  18. printf("x = %.10f y = %.10f\n",a,b);
  19. return;
  20. }
  21.  
  22. void setVar(void) {
  23. argList* reff=&(data[counter]);
  24. *(reff->refVar)=reff->val;
  25. return;
  26. }
  27.  
  28. void func1(double x) {
  29. printf("x = %f\n",x);
  30. return;
  31. }
  32.  
  33. int main(void)
  34. {
  35. void (*aa)(double)=&func1;//just =func1; works too
  36. (*aa)(15.0);//aa(15.0); works too
  37.  
  38. oper funcStack[NN]={NULL};
  39. argList funcArgs[NN]={NULL};
  40. data=funcArgs;
  41. funcStack[counter]=&setVar;argList* curr=&(data[counter]);curr->refVar=&a;curr->val=2.0;counter++;
  42. funcStack[counter]=&setVar;curr=&(data[counter]);curr->refVar=&b;curr->val=3.0;counter++;
  43. for(int i=counter;i<NN;i++) {funcStack[i]=&meanArifGeom;}
  44. counter=0;
  45. while(counter<NN) {(*funcStack[counter])();counter++;}
  46. return 0;
  47. }
  48.  
  49.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
x = 15.000000
x = 2.5000000000  y = 2.4494897428
x = 2.4747448714  y = 2.4746160019
x = 2.4746804367  y = 2.4746804358
x = 2.4746804362  y = 2.4746804362
x = 2.4746804362  y = 2.4746804362
x = 2.4746804362  y = 2.4746804362
x = 2.4746804362  y = 2.4746804362
x = 2.4746804362  y = 2.4746804362