-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.c
More file actions
78 lines (55 loc) · 1.35 KB
/
Copy pathSource.c
File metadata and controls
78 lines (55 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "Rus");
int N = 0, i = 0, mant = 0;
float x = 0.0f, drob = 0.0f, min = 0.0f, max = 0.0f;
float* mas;
int* mantissa;
long double sum = 0.0;
printf("Введите кол-во элементов:\t");
scanf_s(" \t%d", &N);
if (N <= 0)
{
printf("ERROR");
return 0;
}
printf("Введите минимальный элемент:\t");
scanf_s(" \t%f", &min);
printf("Введите максимальный элемент:\t");
scanf_s(" \t%f", &max);
if (min >= max)
{
printf("ERROR");
return 0;
}
mas = (float*)malloc(N * sizeof(float));
mantissa = (int*)malloc(N * sizeof(int));
for (i = 0; i < N; i++)
{
x = (((float)rand()) / RAND_MAX) * (max - min) + min;
mas[i] = x;
drob = x - (int)x;
drob = drob * 1000000;
mant = (int)drob;
mantissa[i] = mant;
}
for (i = 0; i < N; i++)
{
if (mantissa[i] < N)
{
sum -= mas[mantissa[i]];
mas[mantissa[i]] = 0;
}
}
for (i = 0; i < N; i++)
{
sum += mas[i];
}
printf("Полученная сумма:\t%f", sum);
free(mas);
free(mantissa);
return 0;
}