<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /*
  5. START
  6.    how many cards should player one have
  7.    IF
  8.       player one has more than 10 or less than 2
  9.       THEN
  10.          display error
  11.          end program
  12.       END IF
  13.    what cards will player one have
  14.    IF
  15.       any of the cards are more than 10 or less than 1
  16.       THEN
  17.          display error
  18.          end program
  19.     END IF
  20.          
  21.    how many cards should player two have
  22.    IF
  23.       player one has more than 10 or less than 2
  24.       THEN
  25.          display error
  26.          end program
  27.    END IF
  28.    what cards will player two have
  29.    IF
  30.       any of the cards are more than 10 or less than 1
  31.       THEN
  32.          display error
  33.          end program
  34.    END IF
  35.    order the cards for player one highest to lowest
  36.    order the cards for player two highest to lowest
  37.    WHILE
  38.       there is no winner
  39.       IF
  40.          player ones first card is greater than player twos first card
  41.          THEN
  42.             player one is the winner
  43.       END IF
  44.       IF
  45.          player twos first card is greater than player ones first card
  46.          THEN
  47.             player two is the winner 
  48.       END IF
  49.   END WHILE
  50.   IF
  51.    there was no winner
  52.    THEN
  53.       its a draw
  54.   END IF
  55. END
  56.            
  57.            
  58. */
  59.  
  60. int main( void )
  61. {
  62.   int   p1b, p2b, p1a[10], p2a[10], i, j, ph, k,z ;
  63. /* how many cards for p1 */
  64.   scanf("%d", &p1b);
  65.   printf("Player One has %d cards.", p1b);
  66.  
  67. /*error input*/
  68.    if (p1b < 2||p1b > 10)
  69.       {
  70.       printf("\nERROR.Players must have between 2 and 10 cards");
  71.       printf("\nProgram ends");
  72.       exit(0);
  73.     }
  74. /* input p1 cards */
  75.   for ( i = 0; i < p1b; i++)
  76.    {
  77.     scanf("%d", &p1a[i]);
  78.     if (p1a[i] > 10||p1a[i] < 1)
  79.       {
  80.       printf("\nERROR.Cards must be between 1 and 10.");
  81.       printf("\nProgram ends");
  82.       exit(0);
  83.       }
  84.      }
  85.    
  86.  
  87. /* how many cards for p2 */ 
  88.   scanf("%d", &p2b);
  89.   printf("\nPlayer Two has %d cards.\n", p2b);
  90.  
  91. /*error input*/
  92.    if (p2b < 2||p2b > 10)
  93.       {
  94.       printf("\nERROR.Players must have between 2 and 10 cards");
  95.       printf("\nProgram ends");
  96.       exit(0);
  97.     }
  98.  
  99. /* input p2 cards */
  100.   for ( i = 0; i < p2b; i++)
  101.    {
  102.     scanf("%d", &p2a[i]);
  103.     if (p2a[i] > 10||p2a[i] < 1)
  104.       {
  105.       printf("\nERROR.Cards must be between 1 and 10.");
  106.       printf("\nProgram ends");
  107.       exit(0);
  108.       }
  109.     }
  110.    
  111.    
  112. /*order and output*/
  113.   for ( j = 0; j < p1b ; j++)
  114.   {
  115.     for ( i = 0 ; i < (p1b - 1) ; i++)
  116.     {
  117.       if ( p1a[i] < p1a[i+1] )
  118.       {
  119.         ph = p1a[i];
  120.         p1a[i] = p1a[i+1];
  121.         p1a[i + 1] = ph;
  122.       }
  123.     }   
  124.   }
  125.   printf("Player Ones cards are ");
  126.   for ( i = 0; i < p1b; i++)
  127.     printf("%d ", p1a[i]);
  128.    
  129. /*order and output*/
  130.   for ( j = 0; j < p2b ; j++)
  131.   {
  132.     for ( i = 0 ; i < (p2b - 1) ; i++)
  133.     {
  134.       if ( p2a[i] < p2a[i+1] )
  135.       {
  136.         ph = p2a[i];
  137.         p2a[i] = p2a[i+1];
  138.         p2a[i + 1] = ph;
  139.       }
  140.     }   
  141.   }
  142.   printf("\nPlayer Twos cards are ");
  143.   for ( i = 0; i < p2b; i++)
  144.     printf("%d ", p2a[i]);
  145.    
  146.    
  147.   /*who wins*/
  148.   z = p1b;
  149.   if (p1b<p2b)
  150.     z = p2b;
  151.   k = 0;
  152.   for(i=0; i<z; i++){
  153.     if (p1a[i]>p2a[i]){
  154.       printf("\nPlayer 1 wins");
  155.       k = 1;
  156.       break;
  157.     }
  158.     else if (p1a[i]<p2a[i]){
  159.       printf("\nPlayer 2 wins");
  160.       k = 1;
  161.       break;
  162.     }
  163.   }
  164.   if(k == 0)
  165.    printf("\nDraw");
  166. }