nth-fibonacci
Anonymous
c_cpp
08/18/2024 5:08 AM
568 B
34
Indexable
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of n: ");
scanf("%d", &n);
int a = 0, b = 1;
// printing the 0th and 1st term
printf("%d, %d", a, b);
int nextTerm;
// printing the rest of the terms here
for(int i = 2; i < n; i++){
nextTerm = a + b;
a = nextTerm;
b = a;
printf(", %d", nextTerm);
}
return 0;
}Editor is loading...
Leave a Comment