-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_fibbonacci.c
More file actions
58 lines (57 loc) · 1.25 KB
/
Copy path02_fibbonacci.c
File metadata and controls
58 lines (57 loc) · 1.25 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
/*Author: Girish Gaude
* Date: 18/Nov/2019
* Desciption: Program to generate fibbonacci numbers <= 'n'.
* Input: Enter the number
* Output: Display fibbonacci series.
*/
#include<stdio.h>
#include<math.h>
int main()
{
int input = 0; //Variable Declaration
char ch;
int var = pow(2 , 10); //Set working range
do
{
printf("Enter the number\n"); //Enter number
scanf("%d", &input);
int num1 = 0; //Temp Variable
int num2 = 1;
int num3 = 0;
if ( input < var ) //Check the range
{
if ( input == 0 ) //Zero series
{
printf("%d", num1);
}
else if ( input > 0 ) //Positive fib series
{
printf("%d ", num1);
printf("%d ", num2);
while ( (num1+num2) <= input )
{
num3 = num1 + num2;
printf("%d ", num3);
num1 = num2;
num2 = num3;
}
}
else if ( input < 0 ) //Negative fib series
{
printf("%d ", num1);
printf("%d ", num2);
while ( (num1-num2) >= input && (num1-num2) <= -(input) )
{
num3 = num1 - num2;
printf("%d ", num4);
num1 = num2;
num2 = num3;
}
}
}
getchar();
printf("\nDo you want to continue? Press y or n\n");
scanf("%c", &ch);
}while( ch == 'y' );
return 0;
}