Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. /*
  2. Заданы два массива – А(5) и В(4). Первым на печать вывести массив, сумма значений которого окажется наименьшей.
  3. */
  4.  
  5. #include "pch.h"
  6. #include <iostream>
  7. #include <math.h>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. int sum1, sum2;
  13. int *A = new int[5];
  14. int *B = new int[4];
  15. cout << "vvedite A" << endl;
  16. for (int i=0; i < 5; i++)
  17. {
  18. cin >> A[i];
  19. }
  20. cout << "vvedite B" << endl;
  21. for (int i = 0; i < 4; i++)
  22. {
  23. cin >> B[i];
  24. }
  25. sum1 = A[0];
  26. sum2 = B[0];
  27. for (int i = 1; i < 5; i++)
  28. {
  29. sum1 += A[i];
  30. }
  31. for (int i = 1; i < 4; i++)
  32. {
  33. sum2 += B[i];
  34. }
  35. cout<<endl << endl;
  36. if (sum1<sum2)
  37. {
  38. for (int i = 0; i < 5; i++)
  39. {
  40. cout << A[i] << " ";
  41. }
  42. cout << endl;
  43. for (int i = 0; i < 4; i++)
  44. {
  45. cout << B[i] << " ";
  46. }
  47. cout << endl;
  48. }
  49. else {
  50. for (int i = 0; i < 4; i++)
  51. {
  52. cout << B[i] << " ";
  53. }
  54. cout << endl;
  55. for (int i = 0; i < 5; i++)
  56. {
  57. cout << A[i] << " ";
  58. }
  59. cout << endl;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement