Advertisement
Emanuele_Bruno

Esercizio 3

Dec 2nd, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. void array_b(int a[],int b[],int DIM)
  7. {
  8.     int i=0,j;
  9.     while (i<DIM)
  10.     {
  11.         j=i+1;
  12.         while (j<DIM)
  13.         {
  14.             if (a[i]<a[j])
  15.             {
  16.                 b[i]=j;
  17.                 j=DIM-1;
  18.             }
  19.             j++;
  20.         }
  21.         cout << "b[" << i << "]=" << b[i] << "\n";
  22.         i++;
  23.     }
  24. }
  25.  
  26. int main()
  27. {
  28.     int i=0,DIM;
  29.     cout << "Indicare la dimensione dell'array A: ";
  30.     cin >> DIM;
  31.     int a[DIM],b[DIM];
  32.  
  33.     // inizializzo l'array 'a' con valori random compresi tra 0 e 9 e l'array 'b' con il valore '-2'
  34.  
  35.     while (i<DIM)
  36.     {
  37.         a[i]=rand()%10;
  38.         b[i]=-2;
  39.         cout << "a[" << i << "]=" << a[i] << "\n";
  40.         i++;
  41.     }
  42.     cout << "\n";
  43.     array_b(a,b,DIM);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement