-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibonaccirange.c
95 lines (85 loc) · 1.72 KB
/
fibonaccirange.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int numberplace(int n){
if(n!=0){
int i=1;
for ( int j=0, m, x=0, y = 1; j<=n; j++ ){
m = x+y;
if(m==n){
break;
}
x = m-x;
y = m;
i++;
}
return(i);
}
else{
return(0);
}
}
bool isfib(int n) {
bool trvalue = false;
if(n==0 || n==2 || n==3){
trvalue = true;
}
for ( int j=1, m, x=0, y = 1; j<=n; j++ ){
m = x+y;
if(n==m){
trvalue = true;
break;
}
x = m-x;
y = m;
}
return(trvalue);
}
void printfib(int num1, int num2)
{
int c, t=0;
if ((numberplace(num2)-numberplace(num1))==1 || (numberplace(num2)-numberplace(num1))==-1){
printf("no numbers");
}
else{
if (num1<num2){
for ( int j=0, x=0, y = 1; j<=numberplace(num2); j++ ){
c = x+y;
if (c>num1 && c<num2){
printf("%d ",c);
t++;
}
x = c-x;
y = c;
}
}
if (num2<num1){
for ( int j=0, x=0, y = 1; j<=numberplace(num1); j++ ){
c = x+y;
if (c>num2 && c<num1){
printf("%d ",c);
t++;
}
x = c-x;
y = c;
}
}
}
if(t==0){
printf("no numbers");
}
printf("\n");
}
int main()
{
int num1, num2;
while (scanf("%d %d",&num1, &num2) != -1) {
if (isfib(num1) && isfib(num2)) {
printfib(num1, num2);
} else {
printf("no numbers");
printf("\n");
}
}
return 0;
}