Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ОАП12вар1Сем.docx
Скачиваний:
7
Добавлен:
30.01.2023
Размер:
1.3 Mб
Скачать

Лабораторная работа №7. Отладка программы

12

#include <iostream>

using namespace std;

int main()

{

float a=4, k=1, d=51.9e-2, x, y, c, z;

for (c = 3.7; c < 5.1; c + 0.1)

{

x = tan(a * a - 1) / (d - 1);

z = (3*x<a*c) ? a*k+d : cos(a*k)*exp(a+1);

c += 0.1;

cout << "z = " << z << endl;

}

}

12

Вычислить наибольший общий делитель натуральных чисел x, y и z.

# include <iostream>

using namespace std;

int main()

{

setlocale(LC_CTYPE, "rus");

int x, y, z;

cout << "Введите x, y, z \n";

cin >> x >> y >> z;

for (int i = x; i > 0; i--)

{

if (x % i == 0 && y % i == 0 && z % i == 0) {

cout << "nod=" << i << "\n";

break;

}

}

}

12

Лабораторная работа № 8

#include <iostream>

using namespace std;

int main()

{

double sum = 0, x[5] = { 7,2,5.7,6,11 }, max = x[0], y;

for (int i = 0; i < 5; i++)

{

i f (max<x[i]) max = x[i];

sum += pow(x[i], 3);

}

y = max * sum;

cout<<"y="<<y;

}

#include <iostream>

using namespace std;

int main()

{

int n = 6;

float q=0, t = 0.45, x[6] = { 1.1, 6.2, 3, -4, 6, 1 };

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

{

q += (x[i] + 1) / x[i];

cout << " q=" << t+q << endl;

}

return 0;

}

#include <iostream>

using namespace std;

i nt main()

{

double x[5] = { 2, 1.3, 0.4, 5.1, 7 }, y, t;

for (t = 0.5; t <= 3; t+= 0.5)

{

if (t <= 2) {

y = cos(t) * cos(t);

}

Else {

double min = x[0];

for ( int i = 0; i <= 4; i++) {

if (min > x[i]) {

min = x[i];

y = min;

}

}

}

}

cout <<"y=" <<y << endl;

return 0;

}

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

setlocale(LC_ALL, "Rus");

float n, x, a = 0, b = 1;

for (n = 1; n < 5.1; n++)

{

cout << "Введите x " << n << " : ";

cin >> x;

a = x > 0 ? (a + x) : a;

b = x > 0 ? b : (b * x);

}

cout << " a= " << a << endl;

cout << " b= " << b << endl;

}

Доп. Задание

В последовательности из n целых чисел найти и вывести значение суммы четных элементов.

# include <iostream>

using namespace std;

int main()

{

setlocale(LC_ALL, "rus");

int n, i = 0;

do

{

cout << "Введите элемент: ";

cin >> n;

if (n % 2 == 0)

i = i + n;

} while (n != 0); //на 0 заканчивается последовательность

cout << "Сумма четных элементов = " << i;

}

// Заменить в предложении все точки на запятые

#include<iostream>

#include <stdio.h>

using namespace std;

int main()

{

setlocale(LC_CTYPE, "Russian");

char rp[256], symb = '.';

int i, j, n;

cout<<"Введите предожение: ";

gets_s(rp);

n = strlen(rp);

for (i=0; i<= n; i++)

{

if (rp[i] == symb) {

rp[i] = ',';

}

}

for (i = 0; i < n; i++)

cout << rp[i];

}