Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- void invertiArray(int A[], const int x);
- int main(){
- srand(time(NULL));
- int n;
- cout << "Inserisci la dimensione dell'array: ";
- cin >> n;
- const int DIM = n;
- int theArray[DIM];
- n = 0;
- cout << "\nArray A: [";
- while(n < DIM){
- theArray[n] = rand()%100+1;
- if(n < DIM-1)
- cout << theArray[n] << ", ";
- else
- cout << theArray[n] << "]";
- n++;
- }
- invertiArray(theArray, DIM);
- cout << endl;
- cin.ignore();
- cout << "\nPremi INVIO per continuare...";
- cin.get();
- return 0;
- }
- void invertiArray(int A[], const int x){
- int i = x-1, j = 0;
- cout << "\nArray A invertito: [";
- while(i >= x/2){
- int temp = A[i];
- A[i] = A[j];
- A[j] = temp;
- j++, i--;
- }
- i = 0;
- while(i < x){
- if(i < x-1)
- cout << A[i] << ", ";
- else
- cout << A[i] << "]";
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement