Advertisement
mali_cox

Komplex

Jan 14th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. /*NPKP niz kompleksnih brojeva,a vraca kompleksan broj K koji je zbir najveceg i najmanjeg clana niza po modulu.Imamo samo jedan max i min u niz*/
  4.  
  5. struct Kompleksni
  6. {
  7.     double Re,Im;
  8. };
  9.  
  10. struct Kompleksni f(struct Kompleksni *niz,int vel)
  11. {
  12.     int i,j;
  13.     double mod,min=9999,max=0;
  14.     struct Kompleksni K,minK,maxK;
  15.  
  16.     for(i=0; i<vel; i++)
  17.     {
  18.         mod=sqrt(niz[i].Re*niz[i].Re + niz[i].Im*+niz[i].Im);
  19.         if(mod>max)
  20.         {
  21.             max=mod;
  22.             maxK=niz[i];
  23.         }
  24.         if(mod<min)
  25.         {
  26.             min=mod;
  27.             minK=niz[i];
  28.  
  29.         }
  30.         K.Re=minK.Re+maxK.Re;
  31.         K.Im=minK.Im+maxK.Im;
  32.         return K;
  33.  
  34.     }
  35. }
  36.  
  37.     int main()
  38.     {
  39.         struct Kompleksni niz[5];
  40.         int i,vel=5;
  41.         printf("Unesi kompleksne brojeve:");
  42.         for(i=0; i<vel; i++)
  43.         {
  44.             scanf("%lf%lf",&niz[i].Re, &niz[i].Im);
  45.         }
  46.         struct Kompleksni rez;
  47.         rez=f(niz,5);
  48.         printf("Rezultat je : (%g,%g)",rez.Re,rez.Im );
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement