# I can't get this program to run properly

#### Codenameliquid

#include"stdio.h"
#include"conio.h"
int fibo(int);
int main()
{
int a=0;
while(a!=10)
{
printf(" %d",fibo(a));
a++;
}
return 0;
}
int fibo(int a)
{
if(a==0)
{
return 0;
}
else if(a==1)
{
return 1;
}
else
{
return (fibo(a-1)+fibo(a-2));
}
}

This program calculates the Fibonacci series and displays it . But it displays the total sum of the series rather than the individual components of the series

#### wizard

A Fibonacci number is defined as the sum of the two preceding numbers. I am not sure what you want exactly.

#### Onam

The provided program correctly calculates and prints the individual terms of the Fibonacci sequence using a recursive function named fibo() and a loop in the main() method. However, the program's output only shows the individual terms of the series, not the whole sum of the series.

To display the overall sum of the series, make the following changes to the main() function:
Code:
``````int main()
{
int a=0, sum=0;
while(a!=10)
{
int term = fibo(a);
sum += term;    // add each term to the running total
printf(" %d",term);
a++;
}
printf("\nTotal sum of the Fibonacci series: %d", sum);
return 0;
}``````
A new variable named sum is introduced to this updated program to keep track of the series' running total. Before printing the term, each term in the series is added to the total variable within the loop. The whole amount is written using a printf() command at the end of the loop.
I hope this helps to solve your question. If you don't understand how it works, read this article, which has an example comparable to yours.