Filage

Struct2

Mar 4th, 2024
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct complex {
  6.     float re;
  7.     float im;
  8. };
  9.  
  10. complex read() {
  11.     complex c;
  12.     cout << "Введите действительную часть: ";
  13.     cin >> c.re;
  14.     cout << "Введите мнимую часть: ";
  15.     cin >> c.im;
  16.     return c;
  17. }
  18.  
  19.  
  20. void print(complex c) {
  21.     cout << "Действиетельная часть комплексного числа " << c.re << " и мнимамая " << c.im << "i";
  22. }
  23.  
  24. complex add(complex a, complex b) {
  25.     complex result;
  26.     result.re = a.re + b.re;
  27.     result.im = a.im + b.im;
  28.     return result;
  29. }
  30.  
  31. int main() {
  32.     setlocale(LC_ALL, "Rus");
  33.     complex num1, num2, sum;
  34.     cout << "Введите первое комплексное число:" << endl;
  35.     num1 = read();
  36.     cout << "Введите второе комплексное число:" << endl;
  37.     num2 = read();
  38.     cout << "Сумма комплексных чисел:" << endl;
  39.     sum = add(num1, num2);
  40.     print(sum);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment