Контрольная работа по "Программированию"
Автор: Бекарыс Куанышев • Июнь 10, 2022 • Контрольная работа • 2,326 Слов (10 Страниц) • 156 Просмотры
#include <iostream>
using namespace std;
int main()
{
int A[5][4] = {
{1, 2, 3, 4},
{6, 7, 8, 9},
{10, 11, 12, 13},
{14, 15, 17, 17},
{18, 19, 20, 21},
};
int col = 2;
int odd_count = 0;
for (int i = 0; i < 5; ++i)
{
if (A[i][col] % 2 == 1)
odd_count++;
}
cout << odd_count << endl;
}
[pic 1]
#include <iostream>
using namespace std;
double circle_area(double r);
int main()
{
double r1 = 1.0;
double r2 = 2.0;
double r3 = 3.0;
double r4 = 4.0;
double r5 = 5.0;
double radiuses[] = {r1, r2, r3, r4, r5};
double total_area = 0;
for (int i = 0; i < 5; ++i)
{
total_area += circle_area(radiuses[i]);
}
cout << "total area: " << total_area << endl;
}
double circle_area(double r)
{
return 3.14 * r * r;
}
[pic 2]
3.1
#include <iostream>
using namespace std;
int main()
{
int n = 10;
int arr[n] = {-5, -4, 1, 4, -8, 6, -8, 8, 9, 10};
int sum = 0;
for (int i = 0; i < n; ++i)
{
if (arr[i] > 0)
{
sum += arr[i];
}
}
cout << "sum: " << sum << endl;
}
[pic 3]
3.2 #include <iostream>
using namespace std;
int find_max(int arr[], int n);
int find_min(int arr[], int n);
int mult_by(int arr[], int a, int b);
int abs1(int n);
int main()
{
int arr[10] = {-5, -4, 1, 4, -8, 6, -8, 8, 9, 10};
cout << mult_by(arr, find_min(arr, 10), find_max(arr, 10)) << endl;
for (int i = 0; i < 10; ++i)
{
for (int j = i + 1; j < 10; ++j)
{
if (arr[i] < arr[j])
{
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
}
for (int i = 0; i < 10; ++i)
{
cout << arr[i] << " ";
}
cout << "\n";
}
int mult_by(int arr[], int a, int b)
{
int mult = 1;
for (int i = a; i <= b; ++i)
{
mult *= arr[i];
}
return mult;
}
int find_max(int arr[], int n)
{
int max_index = 0;
int max = arr[max_index];
for (int i = 0; i < n; ++i)
{
if (abs1(max) < abs1(arr[i]))
{
max = abs1(arr[i]);
max_index = i;
}
}
return max_index;
}
int find_min(int arr[], int n)
{
int min_index = 0;
int min = arr[min_index];
for (int i = 0; i < n; ++i)
{
if (abs1(min) > abs1(arr[i]))
{
min = abs1(arr[i]);
min_index = i;
}
}
return min_index;
}
int abs1(int n)
{
if (n < 0)
{
return -n;
}
return n;
}
[pic 4]
4.
#include <iostream>
#include <cmath>
using namespace std;
class point
{
public:
int x;
int y;
point(int a, int b) {
x = a;
y = b;
}
};
double distance(point p, point q);
double triangle_area(point p, point q, point r);
double circle_area(point p, point q, point r);
int abs1(int n);
int main()
{
point points[8] = {
point{-1, 0},
point{1, 0},
point{0, 1},
point{2, 0},
point{0, 2},
...