Advertisement
Vickyyy01

SwitchFirstLastElementArray

Jan 13th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int arrSize;
  9.     int matrix[100];
  10.  
  11.     cin >> arrSize;
  12.  
  13.     for(int i = 0; i < arrSize; i++)
  14.     {
  15.         int num = rand() % 1000 + 1;
  16.         matrix[i] = num;
  17.         cout << matrix[i] << " ";
  18.     }
  19.  
  20.     cout << endl << endl;
  21.     int temp;
  22.  
  23.     temp = matrix[0];
  24.     matrix[0] = matrix[arrSize - 1];
  25.     matrix[arrSize - 1] = temp;
  26.  
  27.     for(int j = 0; j < arrSize; j++)
  28.     {
  29.         cout << matrix[j] << " ";
  30.     }
  31.     cout << endl;
  32. }
  33.  
  34. /*
  35. ---------------------------------------------------------------------------------------------------------------------------------
  36. ---------------------------------------------------------------------------------------------------------------------------------
  37. Generates an array with random numbers and switches the first element with the last.
  38. ---------------------------------------------------------------------------------------------------------------------------------
  39. ---------------------------------------------------------------------------------------------------------------------------------
  40. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement