<mosaic.cnfolio.com>
PROGRAM
1. /*
2.
3.    START
4.       input player 1 cards
5.       IF player 1 cards are less than 2 or more than 10
6.          THEN
7.             print "Cards count for player 1 must be between 2 and 10"
8.       END IF
9.       sort the cards
10.       input player 2 cards
11.       IF player 2 cards are less than 2 or more than 10
12.          THEN
13.             print "Cards count for player 2 must be between 2 and 10"
14.       END IF
15.       sort the cards
16.       compare cards and show the winner
17.    END
18.
19. */
20.
21. #include <stdio.h>
22.
23.     int main( void )
24.     {
25.        int p1count;
26.        int p2count;
27.        int p1cards[10];
28.        int p2cards[10];
29.        int i;
30.        int j;
31.        int t;
32.
33.        /* input number of cards for player 1 */
34.        scanf("%d",&p1count);
35.        printf("Player 1 has %d cards\n",p1count);
36.
37.        /* check number of cards for player 1 and display an error if not between 2 and 10 */
38.        if (p1count < 2 || p1count > 10) printf("Cards count for player 1 must be between 2 and 10\n");
39.
40.        /* input player 1 cards */
41.        for(i=0;i<p1count;i++)
42.        {
43.          scanf("%d",&p1cards[i]);
44.        }
45.
46.        /* sort player 1 cards */
47.        for(i=0;i<p1count;i++)
48.        {
49.           for(j=i+1;j<p1count;j++)
50.           {
51.             if (p1cards[i] < p1cards[j])
52.             {
53.                t = p1cards[i];
54.                p1cards[i] = p1cards[j];
55.                p1cards[j] = t;
56.             }
57.           }
58.        }
59.
60.        /* print player 1 cards */
61.        for(i=0;i<p1count;i++)
62.        {
63.          printf("Player 1 Card %d is %d\n",i,p1cards[i]);
64.
65.          /* check if player 1 card is between 1 and 10, if not display an error */
66.          if (p1cards[i] < 1 || p1cards[i] > 10) printf("Card value must be between 1 and 10\n");
67.        }
68.
69.        /* input number of cards for player 2 */
70.        scanf("%d",&p2count);
71.        printf("Player 2 has %d cards\n",p2count);
72.
73.        /* check number of cards for player 2 and display an error if not between 2 and 10 */
74.        if (p2count < 2 || p2count > 10) printf("Cards count for player 2 must be between 2 and 10\n");
75.
76.        /* input player 2 cards */
77.        for(i=0;i<p2count;i++)
78.        {
79.          scanf("%d",&p2cards[i]);
80.        }
81.
82.        /* sort player 2 cards */
83.        for(i=0;i<p2count;i++)
84.        {
85.           for(j=i+1;j<p2count;j++)
86.           {
87.             if (p2cards[i] < p2cards[j])
88.             {
89.                t = p2cards[i];
90.                p2cards[i] = p2cards[j];
91.                p2cards[j] = t;
92.             }
93.           }
94.        }
95.
96.        /* print player 2 cards */
97.        for(i=0;i<p2count;i++)
98.        {
99.          printf("Player 2 Card %d is %d\n",i,p2cards[i]);
100.
101.          /* check if player 2 card is between 1 and 10, if not display an error */
102.          if (p2cards[i] < 1 || p2cards[i] > 10) printf("Card value must be between 1 and 10\n");
103.        }
104.
105.
106.        /* check cards to see which player is the winner */
107.        for(i=0;i<p1count;i++)
108.        {
109.          /* player 1 is the winner if he has bigger card */
110.          if (p1cards[i] > p2cards[i])
111.          {
112.             printf("Player 1 is the winner\n");
113.             break;
114.          }
115.          /* player 2 is the winner if he has bigger card */
116.          if (p2cards[i] > p1cards[i])
117.          {
118.             printf("Player 2 is the winner\n");
119.             break;
120.          }
121.        }
122.
123.     }