Created
March 1, 2026 09:57
-
-
Save thinkphp/a50938506c9e1b7fa0d3c12f599391b0 to your computer and use it in GitHub Desktop.
Complex OOP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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