Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 1, 2026 09:57
Show Gist options
  • Select an option

  • Save thinkphp/a50938506c9e1b7fa0d3c12f599391b0 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/a50938506c9e1b7fa0d3c12f599391b0 to your computer and use it in GitHub Desktop.
Complex OOP
#include <iostream>
#include <math.h>
using namespace std;
class Complex {
public:
float x, y;
float modul();
};
float Complex::modul() {
return sqrt(x*x + y*y);
}
int main(int argc, char const *argv[])
{
Complex v[100]; //declarat un vector de 100 de numere complexe
//v[0], v[1], v[2]
int n, i;
float max;
cout<<"n=";
cin>>n;
for(int i = 0; i < n; ++i) {
cout<<"Numarul complex: "<<i+1<<endl;
cout<<"Partea reala: ";cin>>v[i].x;
cout<<"Partea imaginara: ";cin>>v[i].y;
}
max = v[0].modul();
for(int i = 1; i < n; ++i) {
if(v[i].modul() > max) {
max = v[i].modul();
}
}
cout<<"Max modul = "<<max;
return 0;
}
/*
v = [3 41 50 -10 7 10]
presupunem ca primul este cel mai mare numar;
max = v[0]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment