zilch
Member level 2
Hi, I am trying to implement a Fibonacci series using while loop and written in C. Im not quite good in programming so im asking for help to check if there's something wrong in my code because i cant get the output that i want. I just want the output to start with 1, not 0 (the conventional one). For example, ill input 4; the output should be : 1 1 2 3.
//this is my code
//this is my code
Code:
#include <stdio.h>
int main()
{
int i;
int n;
int a=0;
int b=0;
int x;
printf("Input: ");
scanf("%d", &n);
while (i<=n)
{
if(i==1)
{
printf("Output: \n");
printf("1 ");
}
else if(i==2)
{
printf("1 ");
}
else
{
x = a + b;
a = b;
b = x;
i++;
printf(" %d ", x);
}
}
return 0;
}