Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. int maxValue = 0;
  2. int rows,cols;
  3. int currentNum = 0;
  4. int biggestNumSpace = 0;
  5. int currentSpace = 0;
  6. int tempBigNum = 0;
  7. cout << "Please enter number of rows -->";
  8. cin >> rows;
  9.  
  10. while (rows > 10 || rows < 1)
  11. {
  12. cout << "ERROR: input between 1 and 10 -->";
  13. cin >> rows;
  14. }
  15.  
  16. cout << "Please enter number of cols -->";
  17. cin >> cols;
  18.  
  19. while (cols > 10 || cols < 1)
  20. {
  21. cout << "ERROR: input between 1 and 10 -->";
  22. cin>> cols;
  23. }
  24.  
  25. int arr[rows][cols];
  26. cout << "Please enter " << rows*cols << "Numbers :";
  27.  
  28. for(int i = 0; i < rows; i++)
  29. {
  30. for(int j = 0; j < cols; j++)
  31. {
  32. cin >> arr[i][j];
  33. }
  34. }
  35. maxValue = arr[0][0];
  36. currentSpace = 0;
  37.  
  38. cout << "The matrix is: \n";
  39. for(int i = 0; i < rows; i++)
  40. {
  41. for(int j = 0; j < cols; j++)
  42. {
  43. if(arr[i][j] > maxValue)
  44. {
  45. maxValue = arr[i][j];
  46. }
  47. cout << " " << arr[i][j];
  48. tempBigNum = maxValue;
  49. while(tempBigNum > 0)
  50. {
  51. tempBigNum = tempBigNum / 10;
  52. biggestNumSpace++;
  53. }
  54.  
  55. currentNum = arr[i][j];
  56. while(currentNum > 0)
  57. {
  58. currentNum = currentNum / 10;
  59. currentSpace++;
  60. }
  61.  
  62. for(int i = 0; i < (biggestNumSpace - currentSpace) + 1; i++)
  63. {
  64. cout << " ";
  65. }
  66. }
  67. cout << endl;
  68. }
  69. cout << "And the biggest number value is " << maxValue << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement