Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define PI 3.14159265
  5.  
  6. struct complexo {
  7. double real, im;
  8. };
  9.  
  10. struct complexo le_complexo() {
  11. double real, im;
  12. }
  13.  
  14. void escreve_complexo(struct complexo c) {
  15. printf("\n%f+%fi", c.real, c.im);
  16. }
  17.  
  18. struct complexo soma_complexo(struct complexo c1, struct complexo c2) {
  19. double somaR = c1.real + c2.real;
  20. double somaIm = c1.im + c2.im;
  21.  
  22. printf("\n%f+%fi", somaR, somaIm);
  23. }
  24.  
  25. double squareRoot(double x) {
  26. //Guardar metade do número dado
  27. double root = x / 2; //exemplo: x=36
  28. double temp = 0;
  29.  
  30. while (root != temp) {
  31. //vai diminuindo
  32. temp = root; //temp = 18
  33.  
  34.  
  35. root = (x / temp + temp) / 2; // (36/18 + 18)/2 = 10 e continua
  36. }
  37.  
  38. return root;
  39. }
  40.  
  41. double modulo_complexo(struct complexo c) {
  42. double soma = (c.real * c.real) + (c.im * c.im);
  43.  
  44. return squareRoot(soma);
  45. }
  46.  
  47. double argumento_complexo(struct complexo c) {
  48. double x = c.real;
  49. double argR = cos(x) / modulo_complexo(c);
  50.  
  51. return argR;
  52. }
  53.  
  54.  
  55. int main() {
  56. printf("Hello, World!\n");
  57.  
  58. struct complexo c = {16.0, 12.0};
  59. struct complexo s = {16.0, 12.0};
  60.  
  61. escreve_complexo(c);
  62. soma_complexo(c, s);
  63.  
  64. printf("\nmodulo:%f", modulo_complexo(c));
  65. printf("\nargumento:%f", argumento_complexo(c));
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement