m_74.c
824 Bytes
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
#include <stdio.h>
int scanM (); // scans the size of the array
void scanArr (int M, float *Arr); // scans in the array
int calc (float *Arr, int M); // calculates P
int main (void)
{
int M;
M = scanM ();
float Arr[M];
scanArr (M, Arr);
double P;
P = calc (Arr, M);
printf ("P is equal to: %f", P);
return 0;
}
int scanM ()
{
int M;
printf ("Enter the size of the array (0-51): ");
do
{
scanf ("%d", &M);
}
while (M < 1 || M > 50);
return M;
}
void scanArr (int M, float *Arr)
{
int i;
for (i = 0; i < M; i++)
{
printf ("Enter the %d member of the array: ", i);
scanf ("%f", &Arr[i]);
}
/*for (i = 0; i < M; i++)
{
printf ("Element nr %d is: %.2f\n", i, Arr[i]);
}*/
}
int calc (float *Arr, int M)
{
int i = 0;
double P;
P = Arr[i] * (Arr[i+1] + Arr[i+2]);
i++;
return P;
}