# Write a C program to generate the first n terms of the sequence. | Fibonacci Sequence program in C

### What is Fibonacci Series :

A Fibonacci Sequence is defined as follows: the first and second terms in the sequence are 0 and 1. Subsequent terms are found by adding the preceding two terms in the sequence.

### Program :

1.  #include <stdio.h>
2. void main()
3. {
4. int num1=0, num2=1,no,counter,fab;
5. clrscr();
6.
7. printf(\nENTER LENGTH OF SERIES (N) : “);
8. scanf(“%d”,&no);
9. printf(“\n FIBONACCI SERIES “);
10. printf(\n %d %d”,num1,num2);
11. //LOOP WILL RUN FOR 2 TIME LESS IN SERIES AS THESE WAS PRINTED IN ADVANCE
12. for(counter = 1; counter <= no2; counter++)
13. {
14. fab=num1 + num2;
15. printf(” %d”,fab);
16. num1=num2;
17. num2=fab;
18. }
19. getch();
20. }

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

### 11 Responses

1. prince says:

Write a program to generate the first n terms in the series — 462,420,380,…,306

• #include<stdio.h>
int main(int argc, char const *argv[]) {

int n,i;
int start=462;
int diff = 42;
int temp;

printf("Enter number for n : " );
scanf("%d",&n);

for(i=0; i<n; i++)
{
printf("%d ",start);
temp = diff – (2*i);
start = start – temp;
}
printf("\n");

return 0;
}

2. Eniya Elango says:

Write a program to generate the first n terms in the series — 20,19,17,..,10,5

Input Format:

Input consists of a single integer which corresponds to n.

Output Format:

Output consists of the terms in the series separated by a blank space.

3. write a program that solve that N+ N-1/2+N-2/4…….+M by LOOP
THAT output
is
enter N :3
3+3-1/2
enter M :2
3+2/2

4. write a program that solve that N+ N-1/2+N-2/4…….+M by LOOP
THAT output
is
enter N :3
3+3-1/2
enter M :2
3+2/2

5. Here is the program to print above series

Program :
#include
int main()
{
int i,n;
printf("Please enter the number : ");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
printf("%d ",i*i);
}
printf("n");
return 0;
}

Output:
venkey@:~/C\$ ./a.out
Please enter the number : 7
1 4 9 16 25 36 49

6. ritu lia says:

Write a program to generate the first n terms in the series — 1,4,9,16,25, ….

Input Format:

Input consists of a single integer which corresponds to n.

Output Format:

Output consists of the terms in the series separated by a blank space.

Sample Input:

7

Sample Output:

1 4 9 16 25 36 49

7. Sandy Sandy says:

hlo sir,
im sandy,
im a 1st year,i have joined late to my classes,if u can plzzzz help me…….,when vere u write a program,plzzz write algorithm,flow chart……..,at first u plz if can tel me how to write a program and from it how can we write algorithm and flow chart…..plzzzz sir now no one is to help me im searching every thing blindly in google……..,and im not at all understanding a bit…….plz sir

8. Sandy Sandy says:

hlo sir,
im sandy,
im a 1st year,i have joined late to my classes,if u can plzzzz help me…….,when vere u write a program,plzzz write algorithm,flow chart……..,at first u plz if can tel me how to write a program and from it how can we write algorithm and flow chart…..plzzzz sir now no one is to help me im searching every thing blindly in google……..,and im not at all understanding a bit…….plz sir

9. Hi Narayan,
Here is the code for the above program
#include
int main()
{
int i,j,k,n;
printf("Enter the Value of N : ");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
printf("%d ",i*i);
}
printf("n");
return 0;
}

10. can u please post the code to generate first n terms of series 1 4 9 16 25,…..