Answer to Question #331330 in C for shiva

Question #331330

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


1
Expert's answer
2022-04-25T13:37:46-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS