Advertisement
Guest User

Untitled

a guest
May 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. void first() {
  6. double arr[10]; //Create float array
  7. cout << "Write down 10 numbers for array: " << endl;
  8. for (int i = 0; i < 10; i++) //Input numbers to the array
  9. {
  10. cin >> arr[i];
  11. }
  12.  
  13. double temp = arr[0];
  14. for (int i = 0; i < 10; i++) //Find maximum element
  15. {
  16. if (temp < arr[i])
  17. temp = arr[i];
  18. }
  19. cout << "Maximum element: " << temp << endl;
  20.  
  21. double sum = 0;
  22. for (int i = 0; i < 10; i++) //Calculate sum of all negative numbers
  23. {
  24. if (arr[i] < 0)
  25. sum += arr[i];
  26. }
  27. cout << "The arithmetic mean of the negative elements: " << sum << endl;
  28.  
  29. cout << "Reverse array: " << endl;
  30. for (int i = 9; i >= 0; i--) //Output the reverse array
  31. {
  32. cout << arr[i] << ' ';
  33. }
  34. }
  35.  
  36. void second() {
  37. int arr[5][6]; //Create two-dimensional array
  38. int arr2[6]; //Create one-dimensional array
  39.  
  40. for (int i = 0; i < 5; i++) //Input numbers for two-dimensional array
  41. {
  42. cout << "Write down 6 numbers for " << i + 1 << " line:" << endl;
  43. for (int j = 0; j < 6; j++)
  44. {
  45. cin >> arr[i][j];
  46. }
  47. }
  48.  
  49. int temp;
  50. for (int i = 0; i < 6; i++) //Find maximum element by modul and fill new array
  51. {
  52. temp = arr[0][i];
  53. for (int j = 0; j < 5; j++)
  54. {
  55. //cout << arr[j][i];
  56. if (abs(arr[j][i]) > temp)
  57. temp = abs(arr[j][i]);
  58. }
  59. cout << i + 1 << " column: " << temp << endl;
  60. arr2[i] = temp;
  61. }
  62. }
  63. int main() {
  64. first(); //Call the function
  65. second(); //Call the function
  66. system("pause");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement