forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.2.1.7.c
More file actions
45 lines (37 loc) · 708 Bytes
/
task1.2.1.7.c
File metadata and controls
45 lines (37 loc) · 708 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
#include <stdio.h>
int rec7b(){ //first positive
int x0=-99,x1=-99,x2=-99,xn;
//if(k<=2) return -99;
int k=3;
//for(int i=3;i<k;++i){
while(x2<=0){
xn = x2 + x1 + x0 + 100;
x0 = x1;
x1 = x2;
x2 = xn;
k++;
}
printf("k=%d",k);
return x2;
}
int rec7c(){ /// index of first positive
int x0=-99,x1=-99,x2=-99,xn;
//if(k<=2) return -99;
int k=3;
//for(int i=3;i<k;++i){
while(x2<=0){
xn = x2 + x0 + 100;
x0 = x1;
x1 = x2;
x2 = xn;
k++;
}
printf("xn=%d",xn)
return k;
}
int main(){
int k=9;
printf("x(%d)=%d, %d \n",k,rec7c(k),rec7b(k));
scanf("%d",&k);
printf("x(%d)=%d, %d \n",k,rec7c(k),rec7b(k));
}