fork download
  1. #include <stdio.h>
  2. #include <complex.h>
  3. int main() {
  4. double complex I_a, I_b, I_c, a2_Ib, a_Ic, I_neg;
  5. double i = sqrt(-1);
  6. // Input for I_a
  7. printf("Enter I_a (real and imaginary part): ");
  8. double I_a_real, I_a_imag;
  9. scanf("%lf %lf", &I_a_real, &I_a_imag);
  10. I_a = I_a_real + I_a_imag * i;
  11. // Input for I_b
  12. printf("Enter I_b (real and imaginary part): ");
  13. double I_b_real, I_b_imag;
  14. scanf("%lf %lf", &I_b_real, &I_b_imag);
  15. I_b = I_b_real + I_b_imag * i;
  16. // Input for I_c
  17. printf("Enter I_c (real and imaginary part): ");
  18. double I_c_real, I_c_imag;
  19. scanf("%lf %lf", &I_c_real, &I_c_imag);
  20. I_c = I_c_real + I_c_imag * i;
  21. // Calculating a^2 * I_b
  22. a2_Ib = -I_b / 2.0 + i * I_b;
  23. // Calculating a * I_c
  24. a_Ic = -I_c / 2.0 - i * I_c;
  25. // Calculating Negative Sequence Current (I_neg)
  26. I_neg = (I_a + a2_Ib + a_Ic) / 3.0;
  27. // Output the results
  28. printf("\na^2 * I_b: %.2f + %.2fi\n", creal(a2_Ib), cimag(a2_Ib));
  29. printf("a * I_c: %.2f + %.2fi\n", creal(a_Ic), cimag(a_Ic));
  30. printf("Negative sequence current (I_neg): %.2f + %.2fi\n", creal(I_neg), cimag(I_neg));
  31. return 0;
  32. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Enter I_a (real and imaginary part): Enter I_b (real and imaginary part): Enter I_c (real and imaginary part): 
a^2 * I_b: -nan + -nani
a * I_c: -nan + nani
Negative sequence current (I_neg): -nan + -nani