Advertisement
sellmmaahh

OR-struktura-2013

Aug 26th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. struct Kompleksni {
  7. double re, im;
  8. };
  9.  
  10.  
  11. struct Kompleksni Funk (struct Kompleksni *niz, int vel) {
  12.     struct Kompleksni rez;
  13.     struct Kompleksni max=niz[0];
  14.     struct Kompleksni min=niz[0];
  15.     int i;
  16.     for (i=1; i<vel; i++) {
  17.          int temp=sqrt(niz[i].re*niz[i].re+niz[i].im*niz[i].im);
  18.             if (temp>sqrt(max.re*max.re+max.im*max.im)) max=niz[i];
  19.            if (temp<sqrt(min.re*min.re+max.im*max.im)) min=niz[i];
  20.     }
  21.     rez.re=max.re+min.re;
  22.     rez.im=max.im+min.im;
  23.     return rez;
  24. }
  25.  
  26. int main () {
  27.     int vel;
  28.     printf("Unesite velicinu: ");
  29.     scanf("%d",&vel);
  30.    struct Kompleksni niz[vel];
  31.    int i;
  32.    printf("Unesite elemente niza:");
  33.    for (i=0; i<vel;i++) {
  34.         scanf("%lf", &niz[i].re);
  35.    scanf("%lf",&niz[i].im);
  36.    }
  37.   struct Kompleksni rez=Funk(niz, vel);
  38.   printf("Rez: %.2lf,%.2lf", rez.re, rez.im);
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement