<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.   START
  3.     WHILE No of cards is between 2 and 10 for both player 1 and player 2
  4.       Input card No.values
  5.         IF card no. limit is not in range of 2 and 10 for both player 1 and player 2
  6.           Display Error messages 
  7.         END IF
  8.     END WHILE
  9.  
  10.     WHILE card numbers is between 1 and 10 for both player 1 and player 2
  11.       Input card values
  12.         IF card value limit is not in range of 1 and 10
  13.           Display Error messages
  14.         END IF
  15.     END WHILE
  16.  
  17.  
  18.     WHILE list is not in descending order for player 1 and player 2
  19.       WHILE sort is not complete
  20.         store first element in temporary variable
  21.         move second element to first element
  22.         move temporary value to second element
  23.       END WHILE
  24.     END WHILE
  25.  
  26.  
  27.     WHILE no endgame
  28.       IF  Player 1 has no cards left
  29.         Display player 2 wins
  30.       END IF
  31.       IF  Player 2 has no cards left
  32.         Display player 1 wins
  33.       END IF
  34.       IF  Both players are out of cards
  35.         Display It's a Draw
  36.       END IF
  37.       IF   Player 1 is greater than Player 2
  38.         Display Player 1 wins
  39.       END IF
  40.       IF  Player 1 is less that player 2
  41.         Display Player 2 wins
  42.       END IF
  43.       IF  Player 1 is equal to Player 2
  44.         Display It's a Draw
  45.       END IF
  46.     END WHILE
  47.   END
  48. */
  49.  
  50. #include <stdio.h>
  51. #include <stdlib.h>
  52.  
  53. int main(){
  54.  
  55.     int cards1=0;      /*For deck of cards for player 1*/ 
  56.     int cards2=0;      /*For deck of cards for player 2*/
  57.     int player1[10];   /*Array with 10 spaces for each card in player 1s hand*/
  58.     int player2[10];   /*Array with 10 spaces for each card in player 2s hand*/     
  59.     int i,j;                 
  60.     int temp;               
  61.    
  62.     /*Player 1*/
  63.     while(cards1<1 || cards1>11){  /*inputs*/
  64.       scanf(" %d", &cards1);
  65.      
  66.       if(cards1 < 2){  /*Checking if number of cards are less than 2*/
  67.         printf("Error, invalid card value");
  68.         return 0;
  69.       }
  70.      
  71.       if(cards1 > 10){  /*Checking if number of cards are more than 10*/
  72.         printf("Error, invalid card value");
  73.         return 0;
  74.       }
  75.      
  76.     }
  77.  
  78.     for(i = 0;i<cards1;i++){ 
  79.         scanf(" %d", &player1[i]);
  80.           if(player1[i]<1){   /*Limits the card numbers making sure it's not less than 1 card*/
  81.             printf("Error. below limit\n");
  82.             return 0;
  83.            
  84.           }
  85.           if(player1[i]>10){  /*Limits the card numbers making sure it's not more than 10 cards*/
  86.             printf("Error. above limit\n");
  87.             return 0;
  88.             }
  89.     }
  90.     /*Player 2*/
  91.     while(cards2<1 || cards2>11){  /*inputs*/
  92.       scanf(" %d", &cards2);
  93.      
  94.       if(cards2 < 2){  /*Checking if number of cards are less than 2*/
  95.         printf("Error");
  96.         return 0;
  97.       }
  98.      
  99.       if(cards2 > 10){  /*Checking if number of cards are more than 10*/
  100.         printf("Error");
  101.         return 0;
  102.       }
  103.     }
  104.  
  105.     for(j = 0;j<cards2;j++){
  106.         scanf(" %d", &player2[j]);
  107.           if(player2[j]<1){
  108.             printf("Error. below limit");     /*Limits the card numbers making sure it's not less than 1 card*/
  109.           }
  110.           if(player2[j]>10){
  111.             printf("Error. below limit!\n")/*Limits the card numbers making sure it's not more than 10 cards*/
  112.             }
  113.     }
  114.    
  115.     /*Sorting system*/
  116.     for(i=0;i<cards1-1;i++){     
  117.         for(j=0;j <cards1;j++){ 
  118.             if(player1[j+1] > player1[j]){
  119.                 temp = player1[j];       
  120.                 player1[j] = player1[j+1];
  121.                 player1[j+1] = temp;
  122.  
  123.             }
  124.         }
  125.     }
  126.     for(i=0;i<cards2-1;i++){     
  127.         for(j=0;j <cards2;j++){ 
  128.             if(player2[j+1] > player2[j]){
  129.                 temp = player2[j];       
  130.                 player2[j] = player2[j+1];
  131.                 player2[j+1] = temp;
  132.  
  133.             }
  134.         }
  135.     }
  136.    
  137.     /*outputs*/
  138.     for(i=0; i<10;i++){
  139.         if(cards1 == 0 && cards2 == 0){
  140.               printf("It is a Draw!\n");
  141.               break;
  142.         }
  143.         if(cards1 == 0){
  144.               printf("Player 2 Wins!\n");
  145.               break;
  146.         }
  147.         if(cards2 == 0){
  148.               printf("Player 1 Wins!\n");
  149.              break;
  150.         }
  151.         if(player1[i] == player2[i]){
  152.                  printf("It is a Draw!\n");
  153.               break;
  154.         }
  155.         if(player1[i] > player2[i]){
  156.             printf("Player 1 Wins!");
  157.             break;
  158.         }
  159.         if(player1[i] < player2[i]){
  160.             printf("Player 2 Wins!");
  161.             break;
  162.         }
  163.         if(player1[i] == player2[i]){
  164.                 printf("It's a Draw\n");
  165.             break;
  166.         }
  167.         cards1--;        //'-1' to cards in player1s hand
  168.         cards2--;        //'-1' to cards in player2s hand
  169.     }
  170.   return 0;
  171. }