Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A. Найди цифры-2
- #include <iostream>
- using namespace std;
- int DigitSum(int number) {
- int sum = 0;
- while (number != 0) {
- sum += number % 10;
- number /= 10;
- }
- return sum;
- }
- int main() {
- int numbers[5], sum = 0;
- for (int i = 0; i < 5; i++) {
- cin >> numbers[i];
- }
- for (int i = 0; i < 5; i++) {
- sum += DigitSum(numbers[i]);
- }
- cout << sum;
- return 0;
- }
- // B. Функция минимума
- #include <iostream>
- using namespace std;
- long long minimum(long long first_number, long long second_number) {
- return (first_number < second_number ? first_number : second_number);
- }
- int main() {
- long long a, b, z;
- cin >> a >> b;
- z = minimum(a, 3 * b) * minimum(((2 * a) - b), (2 * b));
- cout << z;
- return 0;
- }
- // C. Длина отрезка
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- double distance(double x_first, double x_second, double y_first, double y_second) {
- return sqrt((x_second - x_first) * (x_second - x_first) + (y_second - y_first) * (y_second - y_first));
- }
- int main() {
- double x[3], y[3], perimeter = 0; // Чтобы изменить количество углов в фигуре, измени везде числа с 3 на нужное
- for (int i = 0; i < 3; i++) {
- cin >> x[i] >> y[i];
- }
- for (int i = 0; i < (3 - 1); i++) {
- perimeter += distance(x[i], x[i + 1], y[i], y[i + 1]);
- }
- perimeter += distance(x[0], x[2], y[0], y[2]);
- cout << fixed << setprecision(6) << perimeter;
- return 0;
- }
- // D. Двойной переворот — не сделал
- // E. Периметр трапеции
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- double perimetr(double a, double b, double h) {
- return (a + b) + 2 * sqrt((h * h) + (a - b) * (a - b)/4);
- }
- int main() {
- int a, b, h;
- double sum = 0;
- cin >> a >> b >> h;
- sum += perimetr(a, b, h);
- cin >> a >> b >> h;
- sum += perimetr (a, b, h);
- cout << fixed << setprecision(6) << sum;
- }
- // F. Гипотенуза
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- double hypot(double a, double b) {
- return sqrt((a * a) + (b * b));
- }
- int main() {
- double P, AB, AC, CD, BD, hypotenuse;
- cin >> AB >> AC >> CD;
- hypotenuse = hypot(AB, AC);
- BD = hypot(hypotenuse, CD);
- P = AB + AC + CD +BD;
- cout << fixed << setprecision(6) << P << endl;
- }
- // G. Цифровой корень
- #include <iostream>
- using namespace std;
- int DigitSum(int number) {
- int sum = 0;
- while (number != 0) {
- sum += number % 10;
- number /= 10;
- }
- return sum;
- }
- int main() {
- int integer;
- cin >> integer;
- while(integer > 9){
- integer = DigitSum(integer);
- }
- cout << integer << endl;
- }
- // H. Опишите побольше функций — не сделал
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement