Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define n 5
- using namespace std;
- struct Complex {
- char name[20];
- double a;
- double b;
- };
- Complex readinfo() {
- Complex x;
- cout << "Enter name: ";
- cin >> x.name;
- cout << "Enter the first variable: ";
- cin >> x.a;
- cout << "Enter the second variable: ";
- cin >> x.b;
- return x;
- };
- void showinfo(Complex x) {
- cout << x.name << ": " << x.a << "+" << x.b << "i" << endl;
- };
- int main() {
- Complex tab[n];
- Complex temp;
- int poz, supr;
- cout << "Enter 5 complex numbers: " << endl;
- for (int i = 0; i < n; i++) {
- tab[i] = readinfo();
- };
- for (int k = 0; k < n; k++) {
- for (int i = 0; i < (n-1); i++) {
- if (tab[i].b > tab[i+1].b) {
- temp = tab[i];
- tab[i] = tab[i+1];
- tab[i+1] = temp;
- };
- };
- };
- cout << "Sorted complex numbers: " << endl;
- for (int i = 0; i < n; i++) {
- showinfo(tab[i]);
- };
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement