Answer the question
In order to leave comments, you need to log in
Why does it output int y and not double?
I'm doing the task, display all the values of the function y = sin(4x) - 2 on the segment [-p, p] with a step p/8.
Wrote code:
#include <iostream>
using namespace std;
void GetAB(float& a, float& b)
{
setlocale(LC_ALL, "rus");
cout << "Отрезок [-P, P]" << endl;
cout << "Шаг табулирования: P / 8" << endl;
}
void Put(double y)
{
setlocale(LC_ALL, "rus");
cout << endl << "Последнее значение функции равно: " << y << endl;
}
#include <cmath>
#include <iostream>
using namespace std;
double mainFunc(double x)
{
return sin(4 * x) - 2;
}
void cycle(double& y, float a, float b)
{
int n = 16; // максимальное число входов, т.к. Пи/8 помещается в заданный отрезок 16 раз
double xMin = -acos(-1);
double xMax = acos(-1);
cout << "Таблица значений функции" << endl;
cout << "\tx=\ty=" << endl;
for (xMin; xMin < xMax; xMin += 0.392699)
{
y = mainFunc(xMin); // вычисление по функции
cout << endl << '\t' << xMin << '\t' << y; // вывод и вычисления
}
}
#include <iostream>
void GetAB(float& a, float& b);
void Put(double y);
void cycle(double&, float, float);
int main()
{
float a, b;
double y;
GetAB(a, b);
cycle(y, a, b);
Put(y);
system("PAUSE");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question