НИЖЕГОРОДСКИЙ ГОСУДАРСТВЕННЫЙ ТЕХНИЧЕСКИЙ УНИВЕРСИТЕТ ИМ. Р.Е. АЛЕКСЕЕВА
Кафедра МАШИНОСТРОИТЕЛЬНЫЕ ТЕХНОЛОГИЧЕСКИЕ КОМПЛЕКСЫ
Дисциплина ИНФОРМАТИКА
Отчет
овыполнении лабораторной работы №2 Тема: «Циклические алгоритмы»
Выполнил: студент группы 22-АМ Кузнецов Роман Михайлович Вариант 6
Проверил(а): Леканов Антон Константинович
Нижний Новгород 2022
Задание а)
Блок-схема для циклов:
for |
while |
do while |
Реализация в Mathcad:
Программа на С++ для цикла for:
#include <iostream>
#include <math.h> #include <iomanip> using namespace std;
double f(double x)
{
return (sqrt(pow(x, 2) + x));
}int main() {
system("Color F0"); double x, Y; for (x = 0; x <= 5; x += 0.9)
{
Y = f(x);
cout << "\tx=" << x << "\tY=" << Y << "\n";
}
return 0;
}
Программа на С++ для цикла while:
#include <iostream>
#include <math.h> #include <iomanip> using namespace std;
double f(double x)
{
return (sqrt(pow(x, 2) + x));
}int main()
{ |
double x, y; |
x = |
|
|
0; |
|
|
|
|
|
while (x <= 5) |
|
|
|
|
{ |
|
|
|
|
y = f(x) |
|
|
|
|
cout << "\tx=" << x << "\ty=" << y << "\n"; |
x = x + 0.9; |
||
|
system("pause"); |
|
||
|
return 0; |
|
|
|
|
} |
|
|
|
} |
|
|
|
|
Программа на С++ для цикла do while: |
|
|||
#include <iostream> |
|
|
|
|
#include <math.h> |
|
|
|
|
#include <iomanip> using namespace |
|
|||
std; |
|
|
|
|
double f(double x) |
|
|
|
|
{ |
|
|
|
|
|
return (sqrt(pow(x, 2) + x)); |
|
||
} |
|
|
|
|
int main() |
|
|
|
|
{ |
double x, y; |
x = |
|
|
0; |
do |
|
|
|
|
{ |
|
|
|
|
y = f(x) |
|
|
|
|
|
|
cout << "\tx=" << x << "\ty=" << y << "\n"; |
|
|
x += 0.9; |
|
|
|
|
} while (x <= 5); |
system("pause"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
Задание б)
Блок-схема:
Реализация в Mathcad:
Программа на С++:
#include <iostream> #include |
|
|
|
<math.h> using namespace |
|
|
|
std; int main() { |
|
|
|
system("Color F0"); |
setlocale(LC_ALL, "rus"); |
|
|
double x, y, z, s, p, min, max, maxx, maxy, minx, miny; |
s = 0; |
p = 1; |
|
max = -pow(10, 10); |
min = |
|
|
pow(10, 10); |
|
|
|
for (x = 1; x <= 2.2; x += 0.7)
{
for (y = 0; y <= 1.1; y += 0.5)
{
if (pow(x, 2) + pow(y, 2) < 2)
z = pow((1 - sin(pow(x, 2) - pow(y, 3))),
2);
else
z = sqrt(pow(x, 2) * y + 8);
s = s + z;
p = p * z;
if (z > max)
{
max = z; maxx = x; maxy = y;
}
if (z < min)
{
|
min = z; minx = x; miny = y; |
|
} |
|
|
|
cout << "\tx=" << x << "\ty=" << y << "\tz=" |
|
<< z << "\n"; |
|
|
} |
|
|
} |
|
|
cout << "Сумма = " << s << endl; |
cout << |
|
"Произведение = " << p << endl; |
|
|
|
cout << "мин знач z = " << min << " при " << minx << ";" |
|
<< miny << endl; |
|
|
cout << "макс знач z = " << max << " при " << maxx << |
||
";" << maxy << endl; |
return 0; |
|
}
Задание в) Блок-схема:
Реализация в Mathcad:
Программа на СИ++:
#include <iostream>
#include <math.h> #include <iomanip> using namespace std; double Z(double x, double y)
{
return(min((y*sqrt(x)), (sin(y)/x)));
} int main() { |
|
system("Color F0"); |
double x, |
y, z; |
|
cout << setw(12) << "x" << setw(12) << "y" << setw(15) << "Z(x,y)" << endl;
x = 0.6; |
|
do |
|
{ |
|
y = 0; |
do |
|
{ |
cout << setw(12) << x << setw(12) << y << setw(15) << Z(x, y) << endl;
y = y + 1.5;
}
while (y <= 3);
x = x + 7;
}
while (x <= 12); return 0;
}