From 1c8c70837a00fe4c4b36bca8c7485f97ed7d2f95 Mon Sep 17 00:00:00 2001 From: DolzhenkoAlexa Date: Sat, 20 Dec 2025 21:47:30 +0300 Subject: [PATCH 1/6] Create happy_tickets.c --- src/hw2_styleguide/happy_tickets.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/hw2_styleguide/happy_tickets.c diff --git a/src/hw2_styleguide/happy_tickets.c b/src/hw2_styleguide/happy_tickets.c new file mode 100644 index 0000000..ff43875 --- /dev/null +++ b/src/hw2_styleguide/happy_tickets.c @@ -0,0 +1,25 @@ +#include + +int main() +{ + int count[28] = {0}; + // Считаем, сколько троек цифр имеют каждую сумму + for (int a = 0; a <= 9; a++) { + for (int b = 0; b <= 9; b++) { + for (int c = 0; c <= 9; c++) { + // увеличиваем на 1 значение ячейки массива под номером, равным сумме тройки + count[a + b + c]++; + } + } + } + + int result = 0; + for (int sum = 0; sum <= 27; sum++) { + // Берем все 27 возможных "сумм" + // 27 потому что максимум 9+9+9=27 + result = result + (count[sum] * count[sum]); + } + printf("Общее количество счастливых билетов со всеми суммами: %d\n", result); + return 0; +} + From 84c115ec33ed31fc6281ee59b328656978e4b9ff Mon Sep 17 00:00:00 2001 From: DolzhenkoAlexa Date: Sat, 20 Dec 2025 21:48:48 +0300 Subject: [PATCH 2/6] Create array_swap.c --- src/hw2_styleguide/array_swap.c | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/hw2_styleguide/array_swap.c diff --git a/src/hw2_styleguide/array_swap.c b/src/hw2_styleguide/array_swap.c new file mode 100644 index 0000000..9eb50c6 --- /dev/null +++ b/src/hw2_styleguide/array_swap.c @@ -0,0 +1,54 @@ +#include + +// Функция для обращения порядка элементов в массиве +void reverser(int array[], int start, int end) +{ + while (start < end) { + int temp = array[start]; + array[start] = array[end]; + array[end] = temp; + start++; + end--; + } +} + + +int main() +{ + int m, n, arrayLen; + + // Ввод размеров + printf("Введите m: \n"); + scanf("%d", &m); + printf("Введите n: \n"); + scanf("%d", &n); + arrayLen = m + n; + int array[arrayLen]; + + // Ввод элементов массива + printf("Введите элементы массива, в количестве m+n:\n"); + for (int i = 0; i < arrayLen; i++) { + scanf("%d", &array[i]); + } + + // Перестановка + // 1. Обращаем весь массив в обратный порядок. + reverser(array, 0, m + n - 1); + // 2. Обращаем первую часть + reverser(array, 0, n - 1); + // 3. Обращаем вторую часть + reverser(array, n, m + n - 1); + + // Пример: 0 1 3 5 7 9 11 (m=3, n=4) + // 1. 11 9 7 5 3 1 0 + // 2. Так как n=4, меняем первые 4 - 5 7 9 11 + // 3. Так как m=3, то последние 3 - 0 1 3 + // Итог: 5 7 9 11 0 1 3 + + // Вывод результата + printf("После перестановки: "); + for (int i = 0; i < arrayLen; i++) { + printf("%d ", array[i]); + } + return 0; +} From 3c7446f26275fb50014c080017898fbcdecaff3f Mon Sep 17 00:00:00 2001 From: DolzhenkoAlexa Date: Sat, 20 Dec 2025 21:51:06 +0300 Subject: [PATCH 3/6] Create quotient.c --- src/hw2_styleguide/quotient.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/hw2_styleguide/quotient.c diff --git a/src/hw2_styleguide/quotient.c b/src/hw2_styleguide/quotient.c new file mode 100644 index 0000000..df4240b --- /dev/null +++ b/src/hw2_styleguide/quotient.c @@ -0,0 +1,33 @@ +#include +#include + +int findQuotient(int a, int b) +{ + if (b == 0) { + printf("Нельзя делить на ноль!\n"); + return 0; + } + + int q = 0; + while ((q + 1) * abs(b) <= abs(a)) { + q++; + } + + if (a * b < 0) { + return -q; + } + return q; +} + +int main() +{ + int a, b; + printf("Введите два целых a и b, чтобы найти q (a = b*q): \n"); + scanf("%d %d", &a, &b); + + int q = findQuotient(a, b); + if (b != 0) { + printf("Неполное частное от деления q: %d\n", q); + } + return 0; +} From a35e30a5af353ef7b27f23040890887086d9488d Mon Sep 17 00:00:00 2001 From: DolzhenkoAlexa Date: Sat, 20 Dec 2025 21:52:30 +0300 Subject: [PATCH 4/6] Create fast_multiplication.c --- src/hw2_styleguide/fast_multiplication.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/hw2_styleguide/fast_multiplication.c diff --git a/src/hw2_styleguide/fast_multiplication.c b/src/hw2_styleguide/fast_multiplication.c new file mode 100644 index 0000000..12fc57b --- /dev/null +++ b/src/hw2_styleguide/fast_multiplication.c @@ -0,0 +1,20 @@ +#include +int formula(int a, int b) { + return (b + a + 1)*(b + 1) - b; // Сокращение начальной формулы до (х^2+x+1)*(x^2+1)-(x^2) + // Умножение 1: х^2. + // Умножение 2: Умножение скобочек +} + +int main() +{ + int x = 0; + printf("Введите значение х:\n"); + scanf("%d", &x); + int xSquared = x * x; + int result = formula(x, xSquared); + + + // Вывод результата + printf("%d", result); + return 0; +} From 3b8fd25dbcea2f28f6e770738bcda668d5e7d45b Mon Sep 17 00:00:00 2001 From: DolzhenkoAlexa Date: Sat, 20 Dec 2025 21:55:35 +0300 Subject: [PATCH 5/6] Create CMakeLists.txt --- src/hw2_styleguide/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/hw2_styleguide/CMakeLists.txt diff --git a/src/hw2_styleguide/CMakeLists.txt b/src/hw2_styleguide/CMakeLists.txt new file mode 100644 index 0000000..1dbf0f1 --- /dev/null +++ b/src/hw2_styleguide/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 4.0) +project(hw2_styleguide C) + +set(CMAKE_C_STANDARD 17) + +add_executable(array_swap src/hw2_styleguide/array_swap.c) +add_executable(fast_multiplication src/hw2_styleguide/fast_multiplication.c) +add_executable(happy_tickets src/hw2_styleguide/happy_tickets.c) +add_executable(quotient src/hw2_styleguide/quotient.c) From 44216fa09c32147d186557d0af1d3dbffb706fac Mon Sep 17 00:00:00 2001 From: DolzhenkoAlexa Date: Sun, 21 Dec 2025 12:45:23 +0300 Subject: [PATCH 6/6] Fixed CMakeLists.txt --- src/hw2_styleguide/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hw2_styleguide/CMakeLists.txt b/src/hw2_styleguide/CMakeLists.txt index 1dbf0f1..de38d75 100644 --- a/src/hw2_styleguide/CMakeLists.txt +++ b/src/hw2_styleguide/CMakeLists.txt @@ -3,7 +3,7 @@ project(hw2_styleguide C) set(CMAKE_C_STANDARD 17) -add_executable(array_swap src/hw2_styleguide/array_swap.c) -add_executable(fast_multiplication src/hw2_styleguide/fast_multiplication.c) -add_executable(happy_tickets src/hw2_styleguide/happy_tickets.c) -add_executable(quotient src/hw2_styleguide/quotient.c) +add_executable(array_swap array_swap.c) +add_executable(fast_multiplication fast_multiplication.c) +add_executable(happy_tickets happy_tickets.c) +add_executable(quotient quotient.c)