-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-test-chain.cpp
56 lines (51 loc) · 1.36 KB
/
7-test-chain.cpp
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
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <conio.h>
using namespace std;
int main()
{
// --- Input ---------------------------------
printf("-----------------------------------------------\n");
printf("------ *** Chain Fraction Computation *** -----\n");
printf("-----------------------------------------------\n");
printf("\n");
int N; printf("Input Number of Chain Elements: "); cin >> N; //
int *p_chain = new int[N];
double ch; double th;
if (N >= 0) {
system("cls");
for (int i = 0; i < N; i++) {
printf("Input a(%d",i);printf("): "); cin >> p_chain[i];
}
if (N == 1) {
ch = p_chain[0];
}
if (N == 2) {
ch = p_chain[0] + (1/(p_chain[1]*(1.0)));
}
if (N > 2) {
th = (1/(p_chain[N-1]*(1.0)));
//printf("th %.10f\n",th);
while (N --> 2) {
ch = p_chain[N-1] + th;
//printf("ch %.10f",ch);printf("; %d\n",p_chain[N-1]);
th = (1/(ch*(1.0)));
//printf("th %.10f",th);printf("- %d\n",N);
}
ch = th + p_chain[0];
}
printf("-----------------------------------------------\n");
printf("Number (defined by Chain): %.10f\n",ch);
getch();
return 0;
} else {
printf("\n-----------------------------------------------\n");
printf("Invalid Number!\n");
getch();
return 0;
}
}