Advertisement
powerunlimited

CW1011 11/25/2012

Nov 29th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>                      
  3. #include <ctime>    
  4. using namespace std ;
  5. int main() {
  6.     int  *foo;
  7.     int  i , j , tmp, size;
  8.     srand( static_cast<unsigned>( time(NULL) ) ) ;
  9.     cout << "Provide the size of the array" << endl;
  10.  cin >> size;
  11.  foo = new int[size];
  12.  for (i=0;i<size;i++)
  13.         foo[i]=(i+1)*2;    
  14.  for ( i = size-1 ; i > 0 ; --i ) {
  15.         j      = rand() % (i+1) ;
  16.         if ( i == j ) continue ;
  17.         tmp    = foo[i] ;
  18.         foo[i] = foo[j] ;
  19.         foo[j] = tmp ;
  20.     }
  21.      cout << "The remainder is:" << foo[size-1]<<endl;
  22.  size--;
  23.  
  24.  for ( i = 0 ; i < size ; ++i )  cout << foo[i] << " " ;
  25.     cout << '\n' ;
  26.     system("pause");
  27.     return 0 ;
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement