translate output text and comments

mainC
KleptsovKD 3 месяцев назад
Родитель 02cc4a1383
Сommit cf330a5a1b

@ -1,54 +1,55 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
int main() { int main() {
float A, B; float A, B;
int n; int n;
// Ввод значений A и B // Input values A and B
printf("Enter value A: "); printf("Enter value A: ");
scanf("%f", &A); scanf("%f", &A);
printf("Enter value B: "); printf("Enter value B: ");
scanf("%f", &B); scanf("%f", &B);
// Ввод размера вектора X // Input size of vector X
printf("Enter size vector X: "); printf("Enter size of vector X: ");
scanf("%d", &n); scanf("%d", &n);
// Создание вектора X // Create vector X
float* X = (float*)malloc(n * sizeof(float)); float* X = (float*)malloc(n * sizeof(float));
if (X == NULL) { if (X == NULL) {
printf("Error memory.\n"); printf("Memory allocation error.\n");
return 1; // Завершение программы с ошибкой return 1; // Exit the program with an error
} }
// Ввод элементов вектора X // Input elements of vector X
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
printf("Enter element X[%d]: ", i); printf("Enter element X[%d]: ", i);
scanf("%f", &X[i]); scanf("%f", &X[i]);
} }
// Инициализация суммы и счетчика // Initialize sum and counter
float total_sum = 0; float total_sum = 0;
int count = 0; int count = 0;
// Перебор элементов вектора X и выполнение условия // Iterate over elements of vector X and check condition
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (fabs(X[i] - A) < B) { // Проверка условия if (fabs(X[i] - A) < B) { // Check condition
total_sum += X[i]; // Суммируем подходящий элемент total_sum += X[i]; // Sum the suitable element
count++; // Увеличиваем счетчик count++; // Increase the counter
} }
} }
// Вывод результатов // Output results
printf("Sum: %.2f\n", total_sum); printf("Sum: %.2f\n", total_sum);
printf("Counter elements: %d\n", count); printf("Count of elements: %d\n", count);
// Освобождение выделенной памяти // Free allocated memory
free(X); free(X);
printf("Press any key to exit...\n"); printf("Press any key to exit...\n");
getchar(); getchar(); // To consume the newline character left by previous input
getchar(); getchar(); // Wait for user input
return 0; // Завершение программы return 0; // Exit the program
} }

Загрузка…
Отмена
Сохранить