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

#include <stdio.h>
int main(){
int num, i, runMode;
float resistors, sum;
printf("How many resistors: ");
scanf("%d", &num);
printf("Enter runMode: 0 to compute series, 1 to compute parallel: ");
scanf("%d", &runMode);
sum = 0.;
if(runMode == 0)
for(i = 1; i <= num; ++i){
printf("Enter value for R%d... ", i);
scanf("%f", &resistors);
sum += resistors;
}
else if(runMode == 1){
for(i = 1; i <= num; ++i){
printf("Enter value for R%d... ", i);
scanf("%f", &resistors);
sum += 1. / resistors;
}
sum = 1. / sum;
}
printf("sum = %5.3f", sum);
return 0;
}

Example 1
*********
How many resistors: 3
Enter runMode: 0 to compute series, 1 to compute parallel: 0
Enter value for R1... 1.2
Enter value for R2... 2.3
Enter value for R3... 3.4
sum = 6.900
Example 2
*********
How many resistors: 3
Enter runMode: 0 to compute series, 1 to compute parallel: 1
Enter value for R1... 1.2
Enter value for R2... 2.3
Enter value for R3... 3.4
sum = 0.640  