This is a code to calculate nth fibonacci number.
Code :
#include<stdio.h>
int main(){
int n;
printf("N: ");
scanf("%d", &n);
long double third, first = 0 , second = 1;
for(int i=1 ; i<=n ; i++){
third = first + second;
first = second;
second = third;
}
printf("The result is : %Lf", third);
return 0;
}
This code shows correct output when I run it on an online compiler i.e. https://www.onlinegdb.com/online_c_compiler but when I run this on MS Visual Studio Code, it returns wrong output.
Output of https://www.onlinegdb.com/online_c_compiler :
N: 10
The result is : 89.000000
Output from MS Visual Code :
N: 10
The result is : -0.000000
I carefully checked the code I used on both the compilers was exactly same. I think the code is correct but there is some problem in my MS Visual Studio Code. What could be the reason of this unknown behavior?