<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2. /*PSUEDO CODE
  3. Main()
  4. Integer: I,j, n, on
  5. character: newv
  6. Read in number of cards for player 1
  7. Read in card values for player 1
  8.  
  9. begin BubbleSort  for player1
  10.    for all card values
  11.       if card[i] > card[i+1]
  12.          swap(card[i], card[i+1])
  13.       end if
  14.    end for
  15.    
  16. end BubbleSort
  17.  
  18. Read in number of cards for player 2
  19. Read in card values for player 2
  20.  
  21. begin BubbleSort for player 2
  22.  
  23.     for all card values
  24.       if othercard[i] > othercard[i+1]
  25.          swap(card[i], othercard[i+1])
  26.       end if
  27.    end for
  28. For cards 1-9 
  29.    IF
  30.     Card[I]>Othercard[I]
  31.     THEN
  32.            print “Player one wins”
  33.            break loop
  34.  
  35.   ELSE
  36.      Card[I]<Othercard[I]
  37.      THEN
  38.            print “Player two wins”
  39.            break loop
  40. End for
  41. IF I=10 print DRAW
  42. return
  43. END*/
  44.  
  45.  
  46.  int main(void)
  47.  {
  48.    
  49.     int othercard[10]= {0}/*array of cards for player 2 , setting initial value to 0*/
  50.     int card[10]= {0};     /*array of cards for player 1, setting initial value to 0*/
  51.     int i,j,n,on;         
  52.     char newv;
  53.    
  54.     scanf("%d\n" , &n); /*read number of cards in player 1s hand*/
  55.     if (n>10)
  56.        printf(" ERROR Enter value between 2-10");
  57.     if (n<2)
  58.        printf(" ERROR Enter Value between 2-10");
  59.    
  60.     for(i=0;i<n;i++)
  61.     {
  62.       scanf( "%d%c",&card[i], &newv); /*read the card values and store them in newv*/
  63.       if (card[i]>10)
  64.       printf (" ERROR enter a value between 1-10");
  65.    
  66.     }
  67.     for( i=0;i<n-1;i++)
  68.     {
  69.       for (j=i+1;j<n;j++)
  70.       {
  71.          int temp;
  72.          if (card[i] < card[j])  /*swapping two cards if the latter one is a higher value*/
  73.          {
  74.               temp= card[i];
  75.               card[i]=card[j];
  76.               card[j]=temp;   
  77.           }
  78.        }
  79.     }
  80.     /*for(i=0;i<n;i++)
  81.     {
  82.      printf( " %d", card[i]);
  83.      }*/
  84.    
  85.     //sorting cards 2nd person
  86.    
  87.     scanf("%d\n" , &on); /*read number of cards in player 2s hand*/
  88.     if (n>10)
  89.        printf(" ERROR Enter value between 2-10");
  90.     if (n>10)
  91.        printf(" ERROR Enter value between 2-10");
  92.    
  93.     for (i=0;i<on;i++)
  94.     {
  95.       scanf( "%d",&othercard[i]); /*read the card values and store them in newv*/
  96.        if (othercard[i]>10)
  97.       printf (" ERROR enter a value between 1-10");
  98.     }
  99.     for( i=0;i<on-1;i++)
  100.     {
  101.       for (j=i+1;j<on;j++)
  102.       {
  103.          int temp;
  104.          if (othercard[i] < othercard[j])
  105.          {
  106.               temp= othercard[i]; /*swapping two cards if the latter one is a higher value*/
  107.               othercard[i]=othercard[j];
  108.               othercard[j]=temp;
  109.           }
  110.        }
  111.     }
  112.      /*for(i=0;i<n;i++)
  113.     {
  114.      printf( " %d", othercard[i]); 
  115.      }*/
  116.    
  117.    
  118.    /*determining the winner*/
  119.    for ( i=0; i<10; i++) /*looping between 0-9*/
  120.    {
  121.    if (card[i] >othercard[i])
  122.        {
  123.             printf( "player 1 wins");
  124.             break;
  125.        }
  126.    else if (card[i] < othercard[i])
  127.       {
  128.             printf( "player 2 wins" );
  129.             break;
  130.       }
  131.    
  132.    }
  133.    
  134.    if (i==10) /*if i loops to ten aka runs out of cards then it is a draw*/
  135.       printf( "Draw");
  136.    return 0;
  137. }