translate output text and comments

Этот коммит содержится в:
KleptsovKD
2025-01-24 19:46:07 +03:00
родитель 02cc4a1383
Коммит cf330a5a1b

Просмотреть файл

@@ -1,54 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
float A, B;
int n;
// Ââîä çíà÷åíèé A è B
// Input values A and B
printf("Enter value A: ");
scanf("%f", &A);
printf("Enter value B: ");
scanf("%f", &B);
// Ââîä ðàçìåðà âåêòîðà X
printf("Enter size vector X: ");
// Input size of vector X
printf("Enter size of vector X: ");
scanf("%d", &n);
// Ñîçäàíèå âåêòîðà X
// Create vector X
float* X = (float*)malloc(n * sizeof(float));
if (X == NULL) {
printf("Error memory.\n");
return 1; // Çàâåðøåíèå ïðîãðàììû ñ îøèáêîé
printf("Memory allocation error.\n");
return 1; // Exit the program with an error
}
// Ââîä ýëåìåíòîâ âåêòîðà X
// Input elements of vector X
for (int i = 0; i < n; i++) {
printf("Enter element X[%d]: ", i);
scanf("%f", &X[i]);
}
// Èíèöèàëèçàöèÿ ñóììû è ñ÷åò÷èêà
// Initialize sum and counter
float total_sum = 0;
int count = 0;
// Ïåðåáîð ýëåìåíòîâ âåêòîðà X è âûïîëíåíèå óñëîâèÿ
// Iterate over elements of vector X and check condition
for (int i = 0; i < n; i++) {
if (fabs(X[i] - A) < B) { // Ïðîâåðêà óñëîâèÿ
total_sum += X[i]; // Ñóììèðóåì ïîäõîäÿùèé ýëåìåíò
count++; // Óâåëè÷èâàåì ñ÷åò÷èê
if (fabs(X[i] - A) < B) { // Check condition
total_sum += X[i]; // Sum the suitable element
count++; // Increase the counter
}
}
// Âûâîä ðåçóëüòàòîâ
// Output results
printf("Sum: %.2f\n", total_sum);
printf("Counter elements: %d\n", count);
printf("Count of elements: %d\n", count);
// Îñâîáîæäåíèå âûäåëåííîé ïàìÿòè
// Free allocated memory
free(X);
printf("Press any key to exit...\n");
getchar();
getchar();
return 0; // Çàâåðøåíèå ïðîãðàììû
getchar(); // To consume the newline character left by previous input
getchar(); // Wait for user input
return 0; // Exit the program
}