-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheulers.cpp
44 lines (39 loc) · 1.06 KB
/
eulers.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
#include<iostream>
#include<unistd.h>
#include<iomanip>
using namespace std;
void eulers(double x, double y, double stepSize);
int main(int argc, char const *argv[])
{
FILE *sennin;
sennin = fopen("output.txt", "a+");
if(sennin == NULL){
printf("The File handling error !!\n");
}
int file = fileno(sennin);
int copy = dup(STDOUT_FILENO);
dup2(file, STDOUT_FILENO);
eulers(0,1,0.1);
cout << "----------------------------------------------" << endl;
eulers(0,1,0.05);
cout << "----------------------------------------------" << endl;
eulers(0,1,0.01);
cout << "----------------------------------------------" << endl;
fflush(stdout);
fclose(sennin);
dup2(copy, STDOUT_FILENO);
// eulers()
return 0;
}
void eulers(double x, double y, double stepSize)
{
double ans;
while (x < 1)
{
ans = y + (stepSize * y);
y = ans;
// printf("x: %f and y(x): %f \n", x, y);
cout << "X: " << setw(4) << x << " y(x): " << setw(4)<< y << endl;
x += stepSize;
}
};