Reputation: 35
#include <stdio.h>
int singleFib(int x,int a,int b);
int multiFib(int x);
void main(){
int n,i;
printf("How much?\n");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("%5d. number: %d - %d \n",i+1,multiFib(i),singleFib(i,1,1));
}
getch();
return 0;
}
int multiFib(int x){
if (x<2){
return 1;
}
else{
return multiFib(x-2)+multiFib(x-1);
}
int singleFib(int x,int a,int b){
if (x<2){
return 1;
}
else{
return singleFib( x-1, b,(a+b));
}
}
}
The error is in
singleFib(i,1,1) in `printf`
Whyis that problem?how can i solve that problem? i am using codeblocks
Codeblocks\Fiberonacci\main.c|14|undefined reference to `singleFib'| The error is that.how can i solve?
Upvotes: 1
Views: 24303
Reputation:
The {
and }
in multiFib
and singleFib
are mixed up, singleFib
is declared inside multiFib
:
int multiFib(int x){
if (x<2){
return 1;
}
else{
return multiFib(x-2)+multiFib(x-1);
}
/*************************************/
int singleFib(int x,int a,int b) {
if (x<2){
return 1;
}
else{
return singleFib( x-1, b,(a+b));
}
}
/*************************************/
}
it works in gcc, since it's an nonstandard nested functions extension, but the function will not be accessible outside multiFib
.
Upvotes: 1
Reputation: 4581
You're missing a closing bracket for multiFib
, but have one that you don't need after singleFib
.
Upvotes: 0
Reputation: 167
Seems like there is a mismatch in the braces of the function definition
Upvotes: 0
Reputation: 7390
You're missing a close bracket }
at the end of your multiFib
function.
You have an extra close bracket }
at the end of your singleFib
function.
The function main
should have return type int
.
Upvotes: 6