Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define PI 3.14159265
- struct complexo {
- double real, im;
- };
- struct complexo le_complexo() {
- double real, im;
- }
- void escreve_complexo(struct complexo c) {
- printf("\n%f+%fi", c.real, c.im);
- }
- struct complexo soma_complexo(struct complexo c1, struct complexo c2) {
- double somaR = c1.real + c2.real;
- double somaIm = c1.im + c2.im;
- printf("\n%f+%fi", somaR, somaIm);
- }
- double squareRoot(double x) {
- //Guardar metade do número dado
- double root = x / 2; //exemplo: x=36
- double temp = 0;
- while (root != temp) {
- //vai diminuindo
- temp = root; //temp = 18
- root = (x / temp + temp) / 2; // (36/18 + 18)/2 = 10 e continua
- }
- return root;
- }
- double modulo_complexo(struct complexo c) {
- double soma = (c.real * c.real) + (c.im * c.im);
- return squareRoot(soma);
- }
- double argumento_complexo(struct complexo c) {
- double x = c.real;
- double argR = cos(x) / modulo_complexo(c);
- return argR;
- }
- int main() {
- printf("Hello, World!\n");
- struct complexo c = {16.0, 12.0};
- struct complexo s = {16.0, 12.0};
- escreve_complexo(c);
- soma_complexo(c, s);
- printf("\nmodulo:%f", modulo_complexo(c));
- printf("\nargumento:%f", argumento_complexo(c));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement