<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3. Two user game
4. Mimimum 2, maximum 10 cards
5. Datatype user 1 [10], user 2 [10]
6. Users sort card from 10 to 1
7. Define function user 1,n
8. IF(n<2 || n>11)
9. (" user 1 enter cards in hand between 1 to 10")
10. IF(user1[user1sum]<1||user1[user1sum]>11)
11. IF( user1[inside] > user1[lowest] ) lowest = inside;
12. IF(user1[counter]>user2[counter])
13. User 1 wins
14. Define function user 2,d
15. IF(d<2 || d>11)
16. IF(user1[user2sum]<1||user2[user2sum]>11)
17. "user 2 enter card numbers between 1 to 10"
18. IF( user2[inside] > user2[lowest] ) lowest = inside;
19. IF(user2[counter]>user1[counter])
20. User 2 wins
21. Define function draw
22. IF(user1[counter]==user2[counter]
23. && user1sum==user2sum)
24. ("draw")
25. IF user 1 and user 2 the same = draw
26. IF both user are out of cards = draw
27. STOP
28. */
29.
30.
31.
32.
33.
34.
35.
36. #include <stdio.h>
37.
38.  int main ()
39. {
40. int user1sum, counter, d, swap,n,m, user2sum;
41. int user1[10], user2[10];
42. int outside, inside, lowest, tmpSwapValue;
43.
44. /* user 1*/
45. scanf("%d", &n);
46.  if(n<2 || n>11){
47. printf(" user 1 enter cards in hand between 1 to 10");
48. return;}
49.
50.
51. for (user1sum=0; user1sum<n; user1sum++ ){
52. scanf("%d", &user1[user1sum]);
53. if(user1[user1sum]<1||user1[user1sum]>11)
54. printf("user 1 enter card numbers between 1 to 10");
55. }
56. /* user 2*/
57. scanf("%d", &d);
58.  if(d<2 || d>11){
59. printf(" user 2 enter cards in hand betwwen 1 to 10");
60. return;}
61.
62.
63. for (user2sum=0; user2sum<d; user2sum++ ){
64. scanf("%d", &user2[user2sum]);
65. if(user1[user2sum]<1||user2[user2sum]>11)
66. printf("user 2 enter card numbers between 1 to 10");
67. }
68. /* sorting between players 1 */
69.  /* start at the first number and looks at every number EXCEPT the last number */
70.    for ( outside = 0; outside < (n - 1); outside++ )
71.    {
72.       /* during each round of sorting, start with the current number as the lowest number */
73.       lowest = outside;
74.
75.       /* start at the next number after the current number and compare with every number */
76.       for (inside = (outside + 1); inside < n; inside++ )
77.          if ( user1[inside] > user1[lowest] ) lowest = inside; /* remember when a new lowest number is found */
78.
79.       /* swap the position of the lowest number found with the current number */
80.       tmpSwapValue = user1[outside];
81.       user1[outside] = user1[lowest];
82.       user1[lowest] = tmpSwapValue;
83.    }
84.
85.    for (outside = 0; outside < n; outside++ ) {}
86.
87. /* sorting between players 2 */
88.  /* start at the first number and looks at every number EXCEPT the last number */
89.    for ( outside = 0; outside < (d - 1); outside++ )
90.    {
91.       /* during each round of sorting, start with the current number as the lowest number */
92.       lowest = outside;
93.
94.       /* start at the next number after the current number and compare with every number */
95.       for (inside = (outside + 1); inside < n; inside++ )
96.          if ( user2[inside] > user2[lowest] ) lowest = inside; /* remember when a new lowest number is found */
97.
98.       /* swap the position of the lowest number found with the current number */
99.       tmpSwapValue = user2[outside];
100.       user2[outside] = user2[lowest];
101.       user2[lowest] = tmpSwapValue;
102.    }
103.
104.    for (outside = 0; outside < d; outside++ ){}
105.
106. /* comparing for player 1 n 2*/
107. for(counter=0; counter<20; counter++){
108. if(user1[counter]>user2[counter]){
109. printf("player 1 wins");
110. return;}
111. if(user2[counter]>user1[counter]){
112. printf("player 2 wins");
113. return;}
114. if(user1[counter]==user2[counter] && user1sum==user2sum){
115. printf("draw");
116. return;}
117. }
118.
119. }