-
Notifications
You must be signed in to change notification settings - Fork 0
Kr #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Kr #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include <stdio.h> | ||
|
|
||
| // Объявление функции | ||
| extern int sort_array(int array[], int count); | ||
|
|
||
| // Основной код - объявление массива на 100 чисел, создание счетчика, чтобы знать со сколькими числами надо будет работать, чтение чисел через for с scanf и вывод | ||
| int main() { | ||
| int array[100]; | ||
| int count = 0; | ||
|
|
||
| int i = 0; | ||
| while (i < 100 && scanf("%d", &array[i]) == 1) { | ||
| i++; | ||
| count++; | ||
| } | ||
|
|
||
| int moved = sort_array(array, count); | ||
|
|
||
| printf("Отсортированный массив:"); | ||
| for (int i = 0; i < count; i++) { | ||
| printf("%d ", array[i]); | ||
| } | ||
| printf("\n"); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| int sort_array(int* array, int count) { | ||
| int moved_count = 0; | ||
| // сортировка пузырьком | ||
| for (int i = 0; i < count - 1; i++) { | ||
| for (int j = 0; j < count - i - 1; j++) { | ||
| if (array[j] > array[j + 1]) { | ||
| int temp = array[j]; | ||
| array[j] = array[j + 1]; | ||
| array[j + 1] = temp; | ||
| moved_count++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return moved_count; | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вы не добавили решение этой задачи на HWProj, так что поставить оценку не получится |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // | ||
| // Created by sasha on 17.10.2025. | ||
| // | ||
|
|
||
| //Напечатать на экран все из диапазона [1;n], | ||
| //которые являются палиндромами в двоичной записи. Выводить в десятичной системе счисления. | ||
|
|
||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| int systemChangerTo2(int n) { | ||
| int binaryNum[1000]; //Массив для числа во вторичной | ||
| char charBinaryNum[1000]; // Массив для числа во вторичной, но в виде строки | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем нужно два представления? Вполне хватит какого-то одного. |
||
| int i = 0; | ||
| int len = 0; | ||
|
|
||
| while (n > 0) { | ||
| binaryNum[i] = n % 2; | ||
| n = n / 2; | ||
| i++; | ||
| len = i; // Длина массива | ||
| } | ||
|
|
||
| for (i = 0; i < len; i++) { | ||
| charBinaryNum[i] = binaryNum[i] + '0'; | ||
| } | ||
|
|
||
| int left = 0; | ||
| int right = strlen(charBinaryNum) - 1; | ||
|
|
||
| while (left <= right) { | ||
| if (charBinaryNum[left] == charBinaryNum[right]) { | ||
| left++; | ||
| right--; | ||
| } else { | ||
| return 0; | ||
| } | ||
| if (left > right) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это условие уже проверяется в заголовке цикла. Второй раз его проверять не нужно. |
||
| return 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| int main(void) { | ||
| int n = 0; | ||
|
|
||
| printf("Введите n \n"); | ||
| scanf("%d",&n); | ||
|
|
||
| int arr[n]; | ||
| int num = 0; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| arr[i] = num; | ||
| num++; | ||
|
|
||
| if (systemChangerTo2(num) == 1) { | ||
| printf("%d\n", num); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // | ||
| // В массиве целых чисел найти число, сумма цифр которого была бы наибольшей. | ||
| // Если таких чисел несколько, вывести на экран все эти числа. | ||
| // | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| // Функция нахождения максимальной суммы | ||
| int finder(int arr[], int size) { | ||
| int sum = 0; | ||
| for (int i = 0; i < size; i++) { | ||
| int tempSum = 0; // Временная сумма для каждого отдельно взятого числа | ||
| int temp = arr[i]; | ||
|
|
||
| while (temp / 10 != 0) { // "Резатель числа", режем - пока оно не станет нулевым, прибавляем хвостик к сумме | ||
| tempSum += (temp % 10); | ||
| temp = temp/10; | ||
| printf("Sum %d\n", tempSum); | ||
| printf("%d \n", temp); | ||
| } | ||
| tempSum = temp + tempSum; | ||
| printf("Sum %d\n", tempSum); | ||
|
Comment on lines
+15
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| if (tempSum > sum) { | ||
| sum = tempSum; | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| int main(void) { | ||
| int size = 0; | ||
|
|
||
| printf("Введите колво чисел в массиве (len) \n"); | ||
| scanf("%d",&size); | ||
|
|
||
| int arr[size]; | ||
|
|
||
| printf("Введите сами числа в массив \n"); | ||
| for (int i = 0; i < size; i++) { | ||
| scanf("%d",&arr[i]); | ||
| } | ||
|
|
||
| int maxSum = finder(arr, size); | ||
|
|
||
| printf("\n"); | ||
| printf("Max sum of numbers %d", maxSum); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Выводится вообще не то, что нужно по условию. |
||
| return 0; | ||
| } | ||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.