Advertisement
madalinaradu

FAI 7 nr complexe

Dec 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4.  
  5. typedef struct {
  6.     float re; //partea reala
  7.     float im; //partea imaginara
  8. } complex; //nume structura
  9.  
  10. void citire(complex *z,char s[]) { //in s se retine numele numarului complex
  11.     printf("numarul complex %s\n",s);
  12.     printf("partea reala: ");
  13.     scanf("%f",&(*z).re);
  14.     printf("partea imaginara: ");
  15.     scanf("%f",&z->im);
  16. }
  17.  
  18.  
  19. void afisare(complex z,char s[]) {
  20.     printf("numarul complex %s = ",s);
  21.     if(z.im>=0)
  22.         printf("%.2f+%.2fi",z.re,z.im);
  23.     else
  24.         printf("%.2f%.2fi",z.re,z.im);
  25.     printf("\n");
  26. }
  27.  
  28.  
  29. void suma(complex x,complex y,complex *z) {
  30.     z->re=x.re+y.re;// sau (*z).re=x.re+y.re
  31.     z->im=x.im+y.im;
  32. }
  33.  
  34. void produs(complex x, complex y,complex *z) {
  35.     z->re=x.re*y.re-x.im*y.im;// sau (*z).re=x.re*y.re
  36.     z->im=x.re*y.im+x.im*y.re;
  37. }
  38.  
  39. complex produs1(complex x, complex y) {
  40.     complex p;
  41.     p.re=x.re*y.re-x.im*y.im;
  42.     p.im=x.re*y.im+x.im*y.re;
  43.     return p;
  44. }
  45.  
  46. float modul(complex z) {
  47.     return sqrt((pow(z.re,2))+pow(z.im,2));
  48. }
  49.  
  50. complex conjugat(complex z) {
  51.     complex a;
  52.     a.re=z.re;
  53.     a.im=-z.im;
  54.     return a;
  55. }
  56.  
  57. complex invers(complex z) {
  58.     complex inv;
  59.     complex zconjugat = conjugat(z);
  60.  
  61.     complex p;// = produs1(z,zconjugat);
  62.     produs(z,zconjugat,&p);
  63.     inv.re = zconjugat.re/p.re;
  64.     inv.im = zconjugat.im/p.re;
  65.     return inv;
  66. }
  67.  
  68.  
  69. void main() {
  70.     complex z1,z2,s,p;
  71.     citire(&z1,"z1");
  72.     citire(&z2,"z2");
  73.     printf("\n");
  74.     afisare(z1,"z1");
  75.     afisare(z2,"z2");
  76.     printf("\n");
  77.  
  78.     suma(z1,z2,&s);
  79.  
  80.     afisare(s,"z1+z2");
  81.     produs(z1,z2,&p);
  82.     afisare(p,"z1*z2");
  83.     printf("modul lui z1 este %.2f\n",modul(z1));
  84.     printf("modul lui z2 este %.2f\n",modul(z2));
  85.  
  86.  
  87.     afisare(invers(z1),"z1 invers");
  88.     afisare(invers(z2),"z2 invers");
  89.  
  90.  
  91.     getchar();
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement