
#include <stdio.h>
#include <math.h>

const int NN=10;
double a,b;
int counter=0;

typedef void (*oper)(void);
struct argList{double* refVar; double val;};

argList* data;

void meanArifGeom(void) {
  double x=0.5*(a+b);
  double y=sqrt(a*b);
  a=x;b=y;
  printf("x = %.10f  y = %.10f\n",a,b);
  return;
}

void setVar(void) {
	argList* reff=&(data[counter]);
	*(reff->refVar)=reff->val;
    return;
}

void func1(double x) {
  printf("x = %f\n",x);
  return;
}

int main(void)
{
	void (*aa)(double)=&func1;//just =func1; works too
	(*aa)(15.0);//aa(15.0); works too

	oper funcStack[NN]={NULL};
	argList funcArgs[NN]={NULL};
	data=funcArgs;
	funcStack[counter]=&setVar;argList* curr=&(data[counter]);curr->refVar=&a;curr->val=2.0;counter++;
	funcStack[counter]=&setVar;curr=&(data[counter]);curr->refVar=&b;curr->val=3.0;counter++;
	for(int i=counter;i<NN;i++) {funcStack[i]=&meanArifGeom;}
	counter=0;
	while(counter<NN) {(*funcStack[counter])();counter++;}
	return 0;
}

