forked from srinirad/Test3Session2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp4final.c
More file actions
45 lines (38 loc) · 630 Bytes
/
p4final.c
File metadata and controls
45 lines (38 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Write a program to find nth number in fibonacci sequence.
Fibonacci sequence consists of 0,1,1,2,3,5,8,13,21........
int input();
int find_fibo(int n);
void output(int n, int fibo);
*/
#include <stdio.h>
int input()
{
int n;
printf("Enter the number\n");
scanf("%d",&n);
return n;
}
int find_fibo(int n)
{
int fibo=0;
int a=0;
int b=1;
for(int i=0;i<n;i++) {
fibo = a;
a = b;
b = fibo + b;
}
return fibo;
}
void output(int n, int fibo)
{
printf("the %dth fibonacci number is %d\n", n, fibo);
}
int main()
{
int n = input();
int fibo = find_fibo(n);
output(n, fibo);
return 0;
}