.


:




:

































 

 

 

 


do while,




 

do while

y() =

xn = 2.0 xk = 5.0 h=0.5:

 

#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("\ndo -while:\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;

Do

{

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;

} while (x < X_end);

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;

}

-----------------------------------------------------------------------------------------

for,

for

y() =

xn = 2.0 xk = 5.0 h=0.5.

!!! 2 .

 

#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 = xn+h/2;

//////////////////////////////////////////////////////////////////////

printf("\nfor_1:\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);

for (x = xn; x < X_end; x += h)

{

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);

}

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);

//////////////////////////////////////////////////////////////////////

printf("\nfor_2:\n");

const int k = int((xk-xn)/h)+1; // floor ((xk-xn)/h)+1;

// k

x=xn;

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);

for (int i = 1; i <= k; x += h, i++)

{

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);

}

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;

}

:

for_1:

 

┌────┬─────────┐

│ 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│

└────┴─────────┘

for_2:

┌────┬─────────┐

│ 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│

└────┴─────────┘

 

-----------------------------------------------------------------------------------------

( 3.3)

( ). . ( pow()) .

     
 

 


, , , 2. .

 

#include <math.h>

#include <iostream>

Using namespace std;

 

const int n = 5; //

int main ()

{

double x; // ,

cout << "x= ";

cin >> x;

double xpow = 1.0; // , 0=1

int koef = 1; // , 20=1

double result = 1.0; // ( ), =1

for (int i = 1; i <= n; i++)

{ xpow *= x;

koef *= 2; // koef <<= 1!!!

result += koef * xpow;

}

cout << result << endl;

system("pause");

return 0;

}





:


: 2018-10-15; !; : 190 |


:

:

, .
==> ...

1438 - | 1376 -


© 2015-2024 lektsii.org - -

: 0.014 .