Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define PI 3.14159265
- typedef struct ComplexRect
- {
- float real , imag ;
- } ComplexRect ;
- typedef struct ComplexAng
- {
- float mod , ang ;
- } ComplexAng ;
- void rect_to_polar(ComplexRect *nrects , ComplexAng *nangs , int n)
- {
- int i ;
- for (i = 0 ; i < n ; i++)
- {
- nangs[i].mod = sqrt(nrects[i].imag * nrects[i].imag + nrects[i].real * nrects[i].real) ;
- nangs[i].ang = atan2(nrects[i].imag , nrects[i].real) * 180 / PI ;
- }
- }
- int main()
- {
- int i , n ;
- ComplexRect *nrects ;
- ComplexAng *nangs ;
- printf ("Quantidade de números complexos a converter : ") ;
- scanf ("%d" , &n) ;
- printf ("Insira o coeficiente das partes real e imaginária :\n") ;
- nrects = (ComplexRect*) malloc (n * sizeof(ComplexRect)) ;
- if (nrects == NULL)
- {
- system ("clear") ;
- printf ("Memória não disponível !\n") ;
- return -1 ;
- }
- for (i = 0 ; i < n ; i++)
- {
- printf ("... do %dº número complexo: " , i + 1) ;
- scanf ("%f %f" , &nrects[i].real , &nrects[i].imag) ;
- }
- nangs = (ComplexAng*) malloc (n * sizeof(ComplexAng)) ;
- rect_to_polar(nrects , nangs , n) ;
- printf ("As respectivas representações polares são :\n") ;
- for (i= 0 ; i < n ; i++) printf ("mod=%.2f ang=%.f\n" , nangs[i].mod , nangs[i].ang) ;
- free (nrects) ;
- free (nangs) ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment