270 views
0 votes
0 votes
#include<stdio.h>
#include<string.h>
int main()
{
    int f[1000];
int n,i;
f[-1]=0;
f[0]=1;
printf("enter n");
scanf("%d",&n);
if(n==0)
printf("%d",0);
else if(n==1)
printf("%d",1);
else
{
for(i=0;i<n-1;i++){
f[i+1]=f[i-1]+f[i];

}

printf("%d",f[i]);
}
}

 

what is answer if we give n value 2 and tell hw this answer got?

2 Answers

0 votes
0 votes
i think it can give sementation fault at runtime due to f[-1]=0;
0 votes
0 votes
According to the code, when n is the input then n-1 is the output

Try executing with n=2 , the output is 1