<mosaic.cnfolio.com>
PROGRAM
1. //START{
2.
3. //player1 = Player(player1, random int between 1 – 10, list of cards in players hand)
4. //player 1{
5.    //Generate player 1 hands using random int 1-10{
6.       //Print number of cards in hand
7.       //Print player 1’s hand;
8.       //Sort player 1 hand high to low;
9.       //Re part player 1’s hand;
10. //player2 = Player(player2, random int between 1 – 10, list of cards in players hand, ifWon=False)
11.
12. //player 2{
13. //Generate player 2 hands using random int 1-10{
14.       //Print number of cards in hand
15. //Print player 2’s hand;
16.          //Sort player 2 hand high to low;
17. //Re print player 2’s hand;
18.       //}
19.    //}
20. //List of cards to iterate between;
21.
22. //Play game{
23.    //Show player 1’s first card;
24.    //Show player 2’s first card;
25.    //IF Player1’s card > player2’s card{
26.       //Player 1 wins
27. //} else if player2’s card > player 1’s card{
28.    //Player 2 wins
29. //} else {
30.    //No one wins, goes to next card
31. //}
32. //}
33. //IF& state{
34.    //IF player1’s cardsAtStart == 0 {
35.    //Player 1 looses
36.    //END
37. //} ELSE IF player2’s cards at start == 0{
38.       //Player 2 looses
39.       //END
40.    //}ELSE IF player1’s and player 2’s cards in hand == 0{
41.       //END
42.    //}
43. //}
44. //}
45.
46.
47.
48. #include <stdio.h>
49. void bubblesort(int a[], int n);
50.
51.   int main(void)
52.   {
53.   printf("This is the card game\n");
54.   printf("You can see what the out come is\n");
55.
56. int nOfcards1[10], a;
57. int nOfcards2[10], b;
58. int winner;
59. int i;
60.      scanf("%d", &a);
61.      for (i = 0; i < a; i++)
62.      scanf("%d", &nOfcards1[i]);
63.      bubblesort(nOfcards1, a);
64.
65.      scanf("%d", &b);
66.      for (i = 0; i < b; i++)
67.      scanf("%d", &nOfcards2[i]);
68.      bubblesort(nOfcards2, b);
69.       i = 0;
70.         winner = 0;
71.
72.
73.           while (i < a && i < b)
74.     {
75.              if (nOfcards1[i] > nOfcards2[i])
76.         {
77.                winner = 1;
78.                 break;
79.          }
80.             else if (nOfcards1[i] < nOfcards2[i])
81.       {
82.           winner = 2;
83.      break;
84.     }
85. i++;
86. }
87.        if (winner == 0)
88.      {
89.        if (i < a)
90.           winner = 1;
91.             else if (i < b)
92.                winner = 2;
93.          }
94.              if (winner == 0)
95.           {
96.                printf("Draw\n");
97.            }
98.                   else if (winner == 1)
99.          {
100.                printf("secondlayer wins\n");
101.            }
102.              else
103.         {
104.              printf("secondplayer wins\n");
105.        }
106.
107.          return 0;
108.        }
109.          void bubblesort(int a[], int b)
110.          {
111.           int c, d, swap;
112.               for (c = 0; c < (b - 1); c++)
113.         {
114.                for (d = 0; d < b - c - 1; d++)
115.       {
116.             if (a[d] < a[d+1])
117.        {
118.         swap = a[d];
119.         a[d] = a[d+1];
120.         a[d+1] = swap;
121.      }
122.      }
123.      }
124.      }