Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /*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*/
- struct Kompleksni
- {
- double Re,Im;
- };
- struct Kompleksni f(struct Kompleksni *niz,int vel)
- {
- int i,j;
- double mod,min=9999,max=0;
- struct Kompleksni K,minK,maxK;
- for(i=0; i<vel; i++)
- {
- mod=sqrt(niz[i].Re*niz[i].Re + niz[i].Im*+niz[i].Im);
- if(mod>max)
- {
- max=mod;
- maxK=niz[i];
- }
- if(mod<min)
- {
- min=mod;
- minK=niz[i];
- }
- K.Re=minK.Re+maxK.Re;
- K.Im=minK.Im+maxK.Im;
- return K;
- }
- }
- int main()
- {
- struct Kompleksni niz[5];
- int i,vel=5;
- printf("Unesi kompleksne brojeve:");
- for(i=0; i<vel; i++)
- {
- scanf("%lf%lf",&niz[i].Re, &niz[i].Im);
- }
- struct Kompleksni rez;
- rez=f(niz,5);
- printf("Rezultat je : (%g,%g)",rez.Re,rez.Im );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement