Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void Rotate(int *table, int *secondArray);
  5.  
  6. int N, Size, placeValue, counter = 0;
  7. int main()
  8. {
  9.  
  10. cout << "Enter a size for the array to rotate" << endl;
  11. cin >> Size;
  12. N = Size*Size;
  13. placeValue = N - Size;
  14. int toRotate[N];
  15. int Rotated[N];
  16.  
  17. for(int i = 0; i < N; i++)
  18. {
  19. int currentValue;
  20. cout << "Pick a random digit between 0 and 9" << endl;
  21. cin >> currentValue;
  22. toRotate[i] = currentValue;
  23.  
  24.  
  25. }
  26.  
  27. for(int i = 0; i < N; i++)
  28. {
  29. cout << toRotate[i];
  30. }
  31.  
  32. cout << endl;
  33. Rotate(toRotate, Rotated);
  34. cout << endl;
  35.  
  36.  
  37. for(int i = 0; i < N; i++)
  38. {
  39. cout << Rotated[i];
  40. }
  41.  
  42. return 0;
  43. }
  44.  
  45.  
  46.  
  47. void Rotate(int *table, int *secondArray)
  48. {
  49.  
  50.  
  51.  
  52. for(int i = 0; i < Size; i++)
  53. {
  54. for(int c = 0; c < Size; c++)
  55. {
  56. cout << *(table + placeValue);
  57. secondArray[counter] = *(table + placeValue);
  58. placeValue = placeValue - Size;
  59. counter++;
  60. }
  61. placeValue = i;
  62. placeValue = placeValue + (N - Size) + 1;
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement