Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // ConsoleApplication4.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. void inputArray(int* array, int n)
  11. {
  12. cout << "Enter " << n << " elements:\n";
  13.  
  14. for (int i = 0; i < n; i++)
  15. {
  16. cin >> array[i];
  17. }
  18. }
  19.  
  20. void printArray(int* array, int n)
  21. {
  22. cout << "The sorted array is: ";
  23.  
  24. for (int i = 0; i < n; i++)
  25. {
  26. cout << array[i] << " ";
  27. }
  28. cout << endl;
  29. }
  30.  
  31. void square(int* array, int n)
  32. {
  33. for (int i = 0; i < n; i++)
  34. {
  35. array[i] = pow(array[i], 2);
  36. }
  37. }
  38.  
  39. int minValue(int* array, int n)
  40. {
  41. int min = array[0];
  42.  
  43. for (int i = 0; i < n; ++i)
  44. {
  45. if (array[i] < min)
  46. {
  47. min = array[i];
  48. }
  49. }
  50.  
  51. return min;
  52. }
  53.  
  54. int main()
  55. {
  56. int array_1[6], array_2[5];
  57.  
  58. inputArray(array_1, 6);
  59. inputArray(array_2, 5);
  60.  
  61. square(array_1, 6);
  62. square(array_2, 5);
  63.  
  64. printArray(array_1, 6);
  65. printArray(array_2, 5);
  66.  
  67. cout << "Minimal is: " << minValue(array_1, 6) << " and " << minValue(array_2, 5) << endl;
  68.  
  69. system("pause");
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement