ELECTROSTATICS:
Doug caught up with a rod comprising of negative(N) and positive(P) charges. He is asked to calculate the maximum net absolute value of electrostatic field possible in the region due to the rod.
Note : Assume, Electrostatic field = (absolute value of total charge) * 100;
input1 : {4,3,5}
input2 : PNP
output : (4-3+5) * 100 = 600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i, sum;
char str[3];
int input1[3];
printf("Input1:\n");
for (i=0; i<3; i++)
scanf("%d", &input1[i]);
printf("Input2:");
scanf("%s", str);
getchar();
sum = 0;
for (i=0; i<3; i++)
{
if (str[i] == 'P')
sum = sum + input1[i];
else if (str[i] == 'N')
sum = sum - input1[i];
}
printf("\nOutput:\nElectrostatic field = %d", (abs(sum)*100));
return 0;
}
Comments
Leave a comment