#include <stdio.h>
double soma ( double a, double b){
return a+b;
}
double mult ( double a, double b){
return a*b;
}
double sub( double a, double b){
return a-b;
}
double div ( double a, double b){
return a/b;
}
double fib_ninja ( double (* fn)(double a, double b),int init ){
int i=0;
int tam=10;
int acum = init;
int ant=0;
for (i=0 ; i<tam ; i++){
acum = fn(acum,ant);
ant = acum;
printf ("%f",acum);
}
return acum;
}
int main(){
int op;
printf("escolha a operação desejada: 1(soma),2(multiplicação),3(subtraçaõ,4(divisão)) ");
scanf("%d",&op);
if(op==1){
fib_ninja((soma (6.0, 2.0)),0);
}
if(op==2){
fib_ninja((mult ,6.0, 2.0),1);
}
if(op==3) {
fib_ninja((sub ,6.0, 2.0),0);
}
if(op==4){
fib_ninja((div ,6.0, 2.0),1);
}
return 0;
}
エラーは言う
In function 'main':
Line 39: error: incompatible type for argument 1 of 'fib_ninja'
Line 42: error: incompatible type for argument 1 of 'fib_ninja'
Line 45: error: incompatible type for argument 1 of 'fib_ninja'
Line 48: error: incompatible type for argument 1 of 'fib_ninja'