Created
June 21, 2016 18:13
-
-
Save jayaprasad37/d85eddad680bb50cf34f7f52ca80d461 to your computer and use it in GitHub Desktop.
Shuffling a pack of 52 cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <ctime> | |
#include <algorithm> | |
using namespace std; | |
void shuffle(int arr[]) | |
{ | |
srand(time(0)); | |
int j=0; | |
int temp = 0; | |
for(int i=0; i<52; i++) | |
{ | |
j=rand()%52; | |
temp = arr[i]; | |
arr[i]=arr[j]; | |
arr[j]=temp; | |
} | |
} | |
int main() | |
{ | |
int arr[52]; | |
for(int i=0 ; i<52; i++) | |
{ | |
arr[i] = i+1; | |
} | |
cout<<"The unshuffled pack is: "<<endl;; | |
for(int i=0 ; i<52; i++) | |
{ | |
cout<<arr[i]<<" "; | |
} | |
cout<<endl; | |
shuffle(arr); | |
cout<<"The shuffled pack is: "<<endl;; | |
for(int i=0 ; i<52; i++) | |
{ | |
cout<<arr[i]<<" "; | |
} | |
cout<<endl; | |
shuffle(arr); | |
cout<<"The shuffled pack is: "<<endl;; | |
for(int i=0 ; i<52; i++) | |
{ | |
cout<<arr[i]<<" "; | |
} | |
cout<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment