<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.    /* Pseudo Code
  4.    
  5.    Start
  6.        
  7.         Obtain Player1 Hand
  8.         Obtain Player2 Hand
  9.        
  10.         Check validity of Player1 card hand size and values
  11.         Check validity of Player2 Card hand size and values
  12.        
  13.         Sort Player1 hand from highest card to lowest card
  14.         Sort Player2 hand from highest card to lowest card
  15.        
  16.         While Both players have cards in hands
  17.              
  18.              Compare highest cards
  19.              
  20.              If Player1 highest card > Player2 highest card
  21.                
  22.                 Print Player1 wins
  23.              
  24.              Else Player2 highest card >  Player1 highest card
  25.                
  26.                 Print Player2 wins
  27.              
  28.              Else If Player1 highest card = Player2 highestcard
  29.                
  30.                 Move onto comparing the next highest cards in both hands. If no more cards print draw
  31.                
  32.              End While 
  33.              
  34.     End */
  35.    
  36.    
  37.     int main()
  38.    
  39.    {
  40.    
  41.    
  42.     int i, j, temp, temp2; //Identifiers for the arrays.
  43.     int Player1CardQuantity, Player2CardQuantity; //Number of cards in both players hands
  44.     int Player1CardValues[10] = {0}; //Values of Player1's cards
  45.     int Player2CardValues[10] = {0}; //Values of Player2's cards
  46.    
  47.    
  48.    
  49.     //Obtaining the Card Quantity and Values for Player 1
  50.    
  51.     scanf("%d", &Player1CardQuantity);
  52.    
  53.     for(i = 0; i < Player1CardQuantity; i++) {
  54.         scanf("%d", &Player1CardValues[i]);
  55.     }
  56.  
  57.     //Obtaining the Card Quantity and Values for Player
  58.  
  59.     scanf("%d", &Player2CardQuantity);
  60.    
  61.     for(i = 0; i < Player2CardQuantity; i++) {
  62.         scanf("%d", &Player2CardValues[i]);
  63.     }
  64.    
  65.  
  66.  
  67.  
  68.     //Checking validity of hand size for both players
  69.  
  70.  
  71.     if(Player1CardQuantity < 2 || Player1CardQuantity > 10) {
  72.         printf("Incorrect Card Quantity for Player 1");
  73.         return 0;
  74.     }
  75.  
  76.  
  77.     if(Player2CardQuantity < 2 || Player2CardQuantity > 10) {
  78.         printf("Incorrect card quantity for player 2");
  79.         return 0;
  80.     }
  81.    
  82.    
  83.     //Checking validity of card values of both players
  84.  
  85.     for(i = 0; i < Player1CardQuantity; i++) {
  86.         if(Player1CardValues[i] < 1 || Player1CardValues[i] > 10) {
  87.             printf("Incorrect card values for player 1");
  88.             return 0;
  89.         }
  90.     }
  91.    
  92.    
  93.     for(i = 0; i < Player2CardQuantity; i++) {
  94.         if(Player2CardValues[i] < 1 || Player2CardValues[i] > 10) {
  95.             printf("Incorrect card values for player 2");
  96.             return 0;
  97.         }
  98.     }
  99.  
  100.  
  101.     //Sorting cards from highest to lowest for player 1
  102.    
  103.     for(i = 0; i < Player1CardQuantity; i++) {
  104.         for(j = 0; j < Player1CardQuantity; j++) {
  105.            
  106.             if(Player1CardValues[j + 1] > Player1CardValues[j]) {
  107.                
  108.                 temp = Player1CardValues[j];
  109.                 Player1CardValues[j] = Player1CardValues[j + 1];
  110.                 Player1CardValues[j + 1] = temp;
  111.                
  112.             }
  113.         }
  114.     }
  115.    
  116.    
  117.     //Sorting cards from highest to lowest for Player 2
  118.  
  119.    
  120.     for(i = 0; i < Player2CardQuantity; i++) {
  121.         for(j = 0; j < Player2CardQuantity; j++) {
  122.            
  123.             if(Player2CardValues[j + 1] > Player2CardValues[j]) {
  124.                
  125.                 temp2 = Player2CardValues[j];
  126.                 Player2CardValues[j] = Player2CardValues[j + 1];
  127.                 Player2CardValues[j + 1] = temp2;
  128.                
  129.             }
  130.         }
  131.     }
  132.    
  133.    
  134.    //Selecting the winner by comparing hands.
  135.    
  136.    for(i = 0; i < 10; i++) {
  137.        if(Player1CardValues[i] > Player2CardValues[i]) {
  138.            printf("Player 1 wins!");
  139.            
  140.            return 0;
  141.        }
  142.        
  143.        if(Player2CardValues[i] > Player1CardValues[i]) {
  144.            printf("Player 2 wins!");
  145.            
  146.            return 0;
  147.        }
  148.        
  149.        
  150.    }
  151.    
  152.    
  153. printf("It's a draw!");   
  154.    
  155.    
  156.    
  157.    
  158.    
  159.     }