nth-fibonacci
unknown
c_cpp
a year ago
425 B
13
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