0
Identify the mistake in the program in c (in gcc compiler) to print Fibonacci series first n terms
#include<stdio.h> int main() { int a=0,b=1,c,n,i; printf("enter value of n \n"); scanf("%d",&n); printf(a,"\n"); printf(b,"\n"); for(i=3;i<=n;i++) { c=a+b; printf(c,"\n"); a=b; b=c; } return 0; }
2 odpowiedzi
+ 5
#include<stdio.h>
int main()
{
int a=0, b=1, c, n, i;
printf("%d\n", a) ;
printf("%d\n", b) ;
for(i=3;i<=n;i++)
{
c=a+b;
printf("%d\n", c);
a=b;
b=c;
}
return 0;
}
snytax of printf("data type", variable name) ;
%d --> if datatype is integer
%c --> if datatype is character
%s --> for string
%f --> if datatype is float
%u --> for address
0
Syntax error, nothing to do with compiler.
* Before the for-loop:
printf("%d\n", a); // printf(a, "\n");
printf("%d\n", b); // printf(b, "\n");
* Inside for-loop
printf("%d\n", c); // printf(c, "\n");
Try this and see if it works. Please indent your code, it helps finding problem having the code be well indented 👍