<mosaic.cnfolio.com>
PROGRAM
1. #include <stdio.h>
2.
3.  /*
4. Start
5. player 1's amopunt of cards = user input
6. For i is less than player 1's amount of cards then
7.   set individiual places in the array to cards in order
8. end for
9. For i is less than amount of cards
10.   For j is less than amount of cards - 1
11.       check to see if array position i is less than array position of position +1
12.       If less than position +1 then
13.          swap the numbers in the position of the array
14.       End if
15.    End for
16. End for
17. Repeat Lines 5 to 16 for player 2
18. For i is less than 10
19.   If Player 1's cards(Position i) is less than player 2's cards (Position i) then
20.       set winner to 0
21.    Else If Player 1's cards(Position i) is greater than player 2's cards (Position i) then
22.       set winner to 2
23.    End if
24. End for
25. Display who won
26. If winner = 0 then
27.   output player 1 wins
28.   else if winner = 2 then
29.    output player 2 wins
30.   else if winner = 1 then
31.    output its a draw
32. End
33. read in number of cards for A
34. read in cards put numbers in array
35. bubble sort
36. repeat 1-3 for B
37. higher or lower and who wins
38. */
39.
40.
41. int main( void )
42. {
43.   int   PlayerACards[10] = {0};
44.   int   PlayerBCards[10] = {0};
45.   int   AmountOfCardsA, AmountOfCardsB, i, j, Temp, Winner;
46.   Winner = 1;
47.
48.   /* Read in amount of player 1's casrds */
49.   scanf("%d", &AmountOfCardsA);
50.   if (AmountOfCardsA>10) {
51.     if (AmountOfCardsA<2) {
52.       printf("the amount of cards is invalid the program will now end");
53.       goto ENDALL;
54.     }
55.   }
56.   printf(" theres %d cards for player 1 which in order are ", AmountOfCardsA);
57.   /* Read in player 1's cards */
58.   for ( i = 0; i < AmountOfCardsA; i++)
59.   {
60.     scanf("%d", &PlayerACards[i]);
61.   }
62.   /* Order player 1's cards */
63.   for ( j = 0; j < AmountOfCardsA ; j++){
64.
65.     for ( i = 0 ; i < (AmountOfCardsA - 1) ; i++){
66.
67.       if ( PlayerACards[i] < PlayerACards[i+1] )
68.       {
69.         Temp = PlayerACards[i];
70.         PlayerACards[i] = PlayerACards[i+1];
71.         PlayerACards[i + 1] = Temp;
72.       }
73.     }
74.
75.
76.   }
77.
78.   /* Display player 1's ordered cards */
79.   for ( i = 0; i < AmountOfCardsA; i++)
80.   {
81.
82.     printf("%d ", PlayerACards[i]);
83.   }
84.
85.   /* read in amount of player 2's cards */
86.   scanf("%d", &AmountOfCardsB);
87.   if (AmountOfCardsB>10) {
88.     if (AmountOfCardsB<2) {
89.       printf("the amount of cards is invalid the program will now end");
90.       goto ENDALL;
91.     }
92.   }
93.   printf(" theres %d for player 2 cards which in order are ", AmountOfCardsB);
94.   /* read in player 2's cards */
95.   for ( i = 0; i < AmountOfCardsB; i++)
96.   {
97.     scanf("%d", &PlayerBCards[i]);
98.   }
99.   /* Order player 2's cards */
100.   for ( j = 0; j < AmountOfCardsB ; j++){
101.
102.     for ( i = 0 ; i < (AmountOfCardsB - 1) ; i++){
103.
104.       if ( PlayerBCards[i] < PlayerBCards[i+1] )
105.       {
106.         Temp = PlayerBCards[i];
107.         PlayerBCards[i] = PlayerBCards[i+1];
108.         PlayerBCards[i + 1] = Temp;
109.       }
110.     }
111.
112.
113.   }
114.
115.   /* display player 2's ordered cards */
116.   for ( i = 0; i < AmountOfCardsB; i++)
117.   {
118.
119.     printf("%d ", PlayerBCards[i]);
120.   }
121.   /* Find winner */
122.   /*if (AmountOfCardsA >= AmountOfCardsB){*/
123.   for(i=0; i<10; i++){
124.     if (PlayerACards[i]>PlayerBCards[i]){
125.       Winner = 0;
126.       break;
127.     }
128.     else if (PlayerACards[i]<PlayerBCards[i]){
129.       Winner=2;
130.       break;
131.     }
132.     else {
133.       Winner = 1;
134.     }
135.   }
136.
137.
138.   /* Output winner*/
139.   if (Winner < 1){
140.     printf("Player 1 wins");
141.   }
142.   else if (Winner > 1 ){
143.     printf("Player 2 wins");
144.   }
145.   else if (0 < Winner < 2){
146.     printf("Its a draw");
147.   }
148.   ENDALL:
149.   printf("End");
150.
151. }
152. /* else if (AmountOfCardsB >= AmountOfCardsA){
153.       for(i=0; i<AmountOfCardsB; i++){
154.       if (PlayerACards[i]>PlayerBCards[i]){
155.             Winner = 0;
156.             break;
157.        }
158.          else if (PlayerACards[i]<PlayerBCards[i]){
159.             Winner=2;
160.             break;
161.          }
162.       }
163.   }*/