while (), xn = 2.0 xk = 5.0 h=0.5.
y() =
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
double xn = 2.0, xk = 5.0, x, y, h = 0.5;
const double X _ end = xk + h /2; //
// xk
//////////////////////////////////////////////////////////////////////
printf("\nwhile:\n");
printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
218,196,196,196,196,194,196,196,196,196,196,196,196,196,196,191);
printf ("%c x %c y %c\n",179, 179, 179);
//
x = xn;
while (x < X_end)
{
if (x <= 3.5) y = cos(x);
else y = sin(x);
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",195,196,196,196,
196,197,196,196,196,196,196,196,196,196,196,180);
//
printf("%c%4.2lf%c%9.5lf%c\n", 179, x, 179, y, 179);
// 頠
x += h; //
// !!!
}
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
192,196,196,196,196,193,196,196,196,196,196,196,196,196,196, 217);
//
_getch();
return 0;
}
:
┌────┬─────────┐
│ x │ y │
├────┼─────────┤
│2.00│ -0.41615│
├────┼─────────┤
│2.50│ -0.80114│
├────┼─────────┤
│3.00│ -0.98999│
├────┼─────────┤
│3.50│ -0.93646│
├────┼─────────┤
│4.00│ -0.75680│
├────┼─────────┤
│4.50│ -0.97753│
├────┼─────────┤
│5.00│ -0.95892│
└────┴─────────┘
-----------------------------------------------------------------------------------------
while, ++
|
|
while
y() =
xn = 2.0 xk = 5.0 h=0.5:
#include <iomanip> //
#include <math.h>
#include <iostream>
Using namespace std;
int main()
{
double xn = 2.0, xk = 5.0, x, y, h = 0.5;
const double X _ end = xk + h/2; //
// xk
char c,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;
c=char(196); c1=char(218); c2=char(194); c3=char(191);
c4=char(179); c5=char(195); c6=char(197); c7=char(180);
c8=char(192); c9=char(217); c10=char(193);
cout<< c1 << c << c << c << c << c << c2 << c << c << c << c << c << c << c << c << c << c << c << c3 << '\n';
cout<<c4<<" x " << c4 << " y " << c4 << '\n';
// 蠠
int i = 0;
x = xn; //
while (x < X_end)
{
if (x <= 3.5)
{
y=cos(x);
}
else
{
y=sin(x);
}
cout<< c5 << c << c << c << c << c << c6 << c << c << c << c << c << c << c << c << c << c << c << c7 << '\n';
// 蠠
cout << setiosflags(ios::fixed) << setprecision(2);
// x: . 2 蠠
cout << c4 << setw (5) << x; // 5
cout << setiosflags (ios:: fixed) << setprecision (6);
// y: . 6 蠠
cout << c4 << setw(11) << y << c4 <<"\n"; // y 11
i++;
x = xn + i * 0.5; // xn!!!
} // end_while
cout<< c8 << c << c << c << c << c << c10 << c << c << c << c << c << c << c << c << c << c << c << c9 << '\n';
//
system("pause");
return 0;
}
:
┌─────┬───────────┐
│ x │ y │
├─────┼───────────┤
│ 2.00│ -0.416147│
├─────┼───────────┤
│ 2.50│ -0.801144│
├─────┼───────────┤
│ 3.00│ -0.989992│
├─────┼───────────┤
│ 3.50│ -0.936457│
├─────┼───────────┤
|
|
│ 4.00│ -0.756802│
├─────┼───────────┤
│ 4.50│ -0.977530│
├─────┼───────────┤
│ 5.00│ -0.958924│
└─────┴───────────┘
,
i++;
x = xn + i*0.5; // xn!!!
x += 0.5; // !!!
-----------------------------------------------------------------------------------------