-
Notifications
You must be signed in to change notification settings - Fork 7
/
series.c
48 lines (38 loc) · 975 Bytes
/
series.c
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
#include <stdio.h>
#include <stdlib.h>
double array_sum(double* array, int count);
int main(int argc, char *argv[])
{
int count, n;
double* v;
double* r;
double vt, it, rt;
printf("Enter voltage: ");
scanf("%lf", &vt);
printf("How many resistors? ");
scanf("%d", &count);
v = malloc(sizeof(double) * count);
r = malloc(sizeof(double) * count);
for (n=0; n<count; n++)
{
printf("R%d = ", n+1);
scanf("%lf", r+n);
}
rt = array_sum(r, count);
it = vt / rt;
for (n=0; n<count; n++) v[n] = it * r[n];
printf("\n\tV\tI\tR\n");
for (n=0; n<count; n++)
{
printf("R%d\t%.3lf\t%.3lf\t%.3lf\n", n+1, v[n], it, r[n]);
}
free(v); free(r);
return 0;
}
double array_sum(double* array, int count)
{
double sum = 0;
int n;
for (n=0; n<count; n++) sum += array[n];
return sum;
}