Складіть програму мовою С++ для знаходження функції y(x), де x Є [a, b] з кроком h. Дані для y(x), a, b, h вказані в таблиці.
y = x + sin(3x);
[a, b], h [-1, 3], h = 0.3
Програма:
С++:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float y, a, b, h;
cout << "a = "; cin >> a;
cout << "b = "; cin >> b;
cout << "h = "; cin >> h;
while (a <= b) {
y = a + sin(3 * a);
cout << "y = " << y << " при x = " << a << endl;
a += h;
}
}
Результат:
a = -1
b = 3
h = 0.3
-1.14112 при x = -1
-1.56321 при x = -0.7
-1.33204 при x = -0.4
-0.39552 при x = -0.1
0.764643 при x = 0.2
1.4975 при x = 0.5
1.47546 при x = 0.8
0.942254 при x = 1.1
0.528424 при x = 1.4
0.774186 при x = 1.7
1.72058 при x = 2
2.87844 при x = 2.3
3.59854 при x = 2.6
3.56297 при x = 2.9
Відповідь:
Бейсик Python
DIM N, S AS INTEGER
N = 1
S = 0
WHILE N <= 100
S = S + 30
N = N * 2
WEND
PRINT S
n = 1
s = 0
while n <= 100:
s = s + 30
n = n * 2
print(s)
Паскаль Алгоритмический язык
var n, s: integer;
begin
n := 1;
s := 0;
while n <= 100 do
begin
s := s + 30;
n := n * 2
end;
write(s)
end.
алг
нач
цел n, s
n := 1
s := 0
нц пока n <= 100
s := s + 30
n := n * 2
кц
вывод s
кон
Си++
#include <iostream>
using namespace std;
int main()
{
int n, s;
n = 1;
s = 0;
while (n <= 100)
{
s = s + 30;
n = n * 2;
}
cout « s « endl;
}
Пояснення:
Поделитесь своими знаниями, ответьте на вопрос: