Bob103

V-6 новый

Mar 29th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. template <template X>
  6. void get(X **a, int m, int n)
  7. {
  8. cout << "Enter array: " << m << " * " << n << endl;
  9. for (int i = 0; i < m; i++)
  10. for (int j = 0; j < n; j++)
  11. cin >> a[i][j];
  12. }
  13.  
  14. template <template X>
  15. void put(X **a, int m, int n)
  16. {
  17. cout << "Array: " << m << " * " << n << endl;
  18. for (int i = 0; i < m; i++)
  19. {
  20. for (int j = 0; j < n; j++)
  21. cout << setw(6) << a[i][j] << " ";
  22. cout << endl;
  23. }
  24. }
  25. template <class X>
  26. X sum(X **a, int m, int n)
  27. {
  28. X sum = 0;
  29. int count = 0;
  30. for(int i = 0; i < m; i++) {
  31. for(int j = i; j < n - 1; j++)
  32. if(a[i][j]< 0) {
  33. sum += a[i][j];
  34. ++count;
  35. }
  36. }
  37.  
  38. if(count == 0)
  39. return 0;
  40.  
  41. return sum / count;
  42. }
  43.  
  44. int main(int argc, char *argv[])
  45. {
  46. int **a = new int*[3];
  47. for (int i = 0; i < 4; i++)
  48. a[i] = new int[20];
  49.  
  50. double **b = new double*[3];
  51. for (int i = 0; i < 4; i++)
  52. b[i] = new double[20];
  53. get(a, 3, 4);
  54. get(b, 3, 4);
  55. put(a, 3, 4);
  56. put(b, 3, 4);
  57. system("pause");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment