Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std ;
- int main() {
- int *foo;
- int i , j , tmp, size;
- srand( static_cast<unsigned>( time(NULL) ) ) ;
- cout << "Provide the size of the array" << endl;
- cin >> size;
- foo = new int[size];
- for (i=0;i<size;i++)
- foo[i]=(i+1)*2;
- for ( i = size-1 ; i > 0 ; --i ) {
- j = rand() % (i+1) ;
- if ( i == j ) continue ;
- tmp = foo[i] ;
- foo[i] = foo[j] ;
- foo[j] = tmp ;
- }
- cout << "The remainder is:" << foo[size-1]<<endl;
- size--;
- for ( i = 0 ; i < size ; ++i ) cout << foo[i] << " " ;
- cout << '\n' ;
- system("pause");
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement