<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2. /*
  3. Start
  4. player 1, player 2 amount of cards = player input
  5. For i is less than player 1 cards then set array for card values in decending order
  6. end for
  7. For i is less than player 2 cards then set array for card values in decending order
  8. end for
  9. if player 1 or player 2 has < 2 then output error
  10. if player 1 or player 2 has > 10 the output error
  11. if player 1 > player 2 then output player 1 = winner
  12. if player 1 < player 2 then output player 2 = winner
  13. if player 1 = player 2 then output match = draw
  14. end
  15. */
  16.  
  17. int main( void )
  18. {
  19.    int player1, player2, j, i, temp, winner;
  20.    int cards1 [10], cards2 [10];
  21.    scanf( "%d", &player1);
  22.       printf("Player A has this ammount of cards:%d ",player1);
  23.  
  24. if (player1 <= 10)
  25. {
  26.    if (player1 >=2)
  27.    {
  28.    
  29.    for ( i = 0 ; i < player1 ; i++ )
  30.    {
  31.    scanf( "%d", &cards1[i]);
  32.    }
  33.  
  34.    
  35.   for (i = 0; i < player1; i++)
  36.     {
  37.         for (j = 0; j < (player1 - i - 1); j++)
  38.         {
  39.             if (cards1[j] < cards1[j + 1])
  40.             {
  41.                 temp = cards1[j];
  42.                 cards1[j] = cards1[j + 1];
  43.                cards1[j + 1] = temp;
  44.             }
  45.         }
  46.     }
  47.     printf(". Your cards in decending order are...\n");
  48.     for (i = 0; i < player1; i++)
  49.     {
  50.         printf("%d\n", cards1[i]);
  51.     }
  52.     }
  53.     else printf ("Player 2 has less than 2 cards, select more cards to continue");
  54.     }
  55.     else printf ("Player 1 has more than 10 cards, select less cards to continue");
  56.    
  57.    
  58.     /* Player B */
  59.    
  60.     scanf( "%d", &player2);
  61.       printf("Player B has this ammount of cards:%d ",player2);
  62.  
  63.    
  64.    for ( i = 0 ; i < player2 ; i++ )
  65.    {
  66.    scanf( "%d", &cards2[i]);
  67.    }
  68.  
  69.    
  70.   for (i = 0; i < player2; i++)
  71.     {
  72.         for (j = 0; j < (player2 - i - 1); j++)
  73.         {
  74.             if (cards2[j] < cards2[j + 1])
  75.             {
  76.                 temp = cards2[j];
  77.                 cards2[j] = cards2[j + 1];
  78.                cards2[j + 1] = temp;
  79.             }
  80.         }
  81.     }
  82.     printf(". Your cards in decending order are...\n");
  83.     for (i = 0; i < player2; i++)
  84.     {
  85.         printf("%d\n", cards2[i]);
  86.     }
  87.    
  88.     /*Finding the winnner */
  89.     if(player1 >= player2){
  90.    for (i=0; i < player1; i++){
  91.  
  92.     if (cards1[i] < cards2[i]){
  93.     winner = 0;
  94.     break;
  95.    
  96.           }
  97.    
  98.      
  99.    
  100.     else if (cards1[i] < cards2[i]){
  101.     winner = 2;
  102.     break;
  103.    
  104.           }
  105.         }
  106.      
  107.    
  108.     if (player2 >= player1){
  109.     for(i=0; i < player2; i++){
  110.     if (cards1[i] > cards2[i]){
  111.     winner=0;
  112.     break;
  113.     }
  114.    
  115.     else if (cards1[i] < cards2[i]){
  116.     winner=2;
  117.     break;
  118.           }
  119.          }
  120.        }
  121.    
  122.     /*Who is the winner?*/
  123.     if (winner < 1){
  124.     printf ("Player A is the winner!");
  125.     }
  126.    
  127.     else if (winner > 1)
  128.     {
  129.     printf ("Player B is the winner!");
  130.     }
  131.     else if (0 < winner < 2){
  132.     printf ("The match ends in a draw!");
  133.     }
  134.     }
  135.     }