Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int **array(int str, int col)
  9. {
  10. srand(time(NULL));
  11. int **arr = new int*[str];
  12. for (int i = 0; i < str; ++i)
  13. {
  14. arr[i] = new int[col];
  15. for (int j = 0; j < col; ++j)
  16. {
  17. arr[i][j] = rand() % 100;
  18. cout << setw(5) << arr[i][j] << " ";
  19. }
  20. cout << endl;
  21. }
  22. return arr;
  23. }
  24.  
  25. bool mean(int *str){
  26. int size = sizeof(str);
  27. int sum_b = 0, sum_a = 0;
  28. for (int i = 0; i < size; ++i)
  29. {
  30. for (int j = 0, k = i + 1; j < i, k < size; ++j, ++k)
  31. {
  32. sum_b += str[j];
  33. sum_a += str[k];
  34. }
  35. if (sum_b == sum_a) return true;
  36. }
  37. return false;
  38. }
  39.  
  40. int main()
  41. {
  42. char answer = 'y';
  43. do {
  44. int str;
  45. cout << "Type size of array: ";
  46. cin >> str;
  47. cout << endl;
  48. int **arr = array(str, str);
  49. bool *flags = new bool[str];
  50. for (int i = 0; i < str; i++)
  51. {
  52. flags[i] = mean(arr[i]);
  53. cout << flags[i] << " ";
  54. }
  55. cout << "\nTry again? Y/N";
  56. cin >> answer;
  57. } while (answer == 'y');
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement