Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cmath>
- using namespace std;
- ifstream fin("complexe.in");
- ofstream fout("complexe.out");
- struct complex
- {
- double real;double imaginar;
- }z,z1,z2,v[100];
- void citire(struct complex &z)
- {
- fin>>z.real>>z.imaginar;
- }
- void scriere(struct complex z)
- {
- if(z.imaginar>0)
- {
- fout<<z.real<<'+'<<z.imaginar<<"*i"<<endl;
- }
- if(z.imaginar<0)
- {
- fout<<z.real<<z.imaginar<<"*i"<<endl;
- }
- if(z.imaginar==0)
- {
- fout<<z.real<<endl;
- }
- }
- complex suma(struct complex z1,struct complex z2)
- {
- complex suma_elemente;
- suma_elemente.real=z1.real+z2.real;
- suma_elemente.imaginar=z1.imaginar+z2.imaginar;
- return suma_elemente;
- }
- complex maxim(struct complex z1,struct complex z2)
- {
- double modul1=0,modul2=0;
- modul1+=sqrt((z1.real*z1.real)+(z1.imaginar*z1.imaginar));
- modul2+=sqrt((z2.real*z2.real)+(z2.imaginar*z2.imaginar));
- if(modul1>modul2)
- {
- return z1;
- }
- else
- {
- return z2;
- }
- }
- int modul( struct complex z)
- {
- double modul=0;
- modul+=sqrt((z.real*z.real)+(z.imaginar*z.imaginar));
- return modul;
- }
- int main()
- {
- int n,i,j;
- complex suma_,maxim_,aux;
- fin>>n;
- suma_={0};
- maxim_={0};
- for(i=1;i<=n;i++)
- {
- citire(z);
- v[i]=z;
- scriere(v[i]);
- }
- fout<<endl;
- for(i=1;i<=n;i++)
- {
- suma_=suma(suma_,v[i]);
- }
- scriere(suma_);
- fout<<endl;
- for(i=1;i<n;i++)
- {
- maxim_=maxim(maxim_,v[i]);
- }
- scriere(maxim_);
- fout<<endl;
- for(i=1;i<=n;i++)
- {
- for(j=i+1;j<=n;j++)
- {
- if(modul(v[i])>modul(v[j]))
- {
- aux=v[i];
- v[i]=v[j];
- v[j]=aux;
- }
- }
- }
- for(i=1;i<=n;i++)
- {
- scriere(v[i]);
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement