7. Write a program to construct a Fibonacci series upto n terms.

 SOURCE CODE:


#include <stdio.h>

int main()
{   int t1=0,t2=1,n,next_term;
    printf("enter how many terms you want\n");
    scanf("%d",&n);
    printf("%d,%d,",t1,t2);
    next_term=t1+t2;
    for(int i=3;i<=n;i++)
    {  printf("%d,",next_term);
       t1=t2;
       t2=next_term;
       next_term=t1+t2;
    }

    return 0;
}


Comments

Popular posts from this blog

2. Basic salary of an employee is input through the keyboard. The DA is 25% of the basic salary while the HRA is 15% of the basic salary. Provident Fund is deducted at the rate of 10% of the gross salary (BS+DA+HRA). Write a program to calculate the Net Salary.

4. Write a program to find the largest of three numbers using nested if else