Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. struct complex
  2. {
  3. int real; //действительная часть
  4. int image; //мнимая часть
  5. };
  6.  
  7. int add(int x, int y)
  8. {
  9. int rez = x + y;
  10. return rez;
  11. }
  12. complex add(complex x, complex y)
  13. {
  14. complex rez;
  15. rez.real = x.real + y.real;
  16. rez.image = x.image + y.image;
  17. return rez;
  18. }
  19.  
  20. void main()
  21. {
  22. setlocale(LC_ALL, "russian"); // чтобы на консоли отображались русские буквы
  23. int r1, r2;
  24. cout << "Целое число №1: ";
  25. cin >> r1;
  26. cout << "Целое число №2: ";
  27. cin >> r2;
  28. cout << endl;
  29. complex c1, c2;
  30. cout << "---Комплексное число №1: " << endl;
  31. cout << "Действительная часть: ";
  32. cin >> c1.real;
  33. cout << "Мнимая часть: ";
  34. cin >> c1.image;
  35. cout << "---Комплексное число №2: " << endl;
  36. cout << "Действительная часть: ";
  37. cin >> c2.real;
  38. cout << "Мнимая часть: ";
  39. cin >> c2.image;
  40. cout << endl;
  41. int rez1 = add(r1, r2);
  42. cout << "Сложение целых чисел: " << r1 << " + " << r2 << " = " << rez1 << endl;
  43. cout << "Сложение комплексных чисел:" << endl;
  44. complex rez2 = add(c1, c2);
  45. cout << "(" << c1.real << " + " << c1.image << "i) + (" << c2.real << " + " << c2.image << "i) = " << rez2.real << " + " << rez.image << "i" << endl;
  46. system("pause"); // чтобы после выполнения программы консоль не исчезала сразу же
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement