<mosaic.cnfolio.com>
PROGRAM
1. /*START*/
2. /*Initializing player 1 and player 2 arrays*/
3. /*Input size_array_1, array1[ ], size_array_2, array2[ ]*/
4. /*Define function Bubblesort( )*/
5. /*Initialize c = 0, d = 0, swap*/
6. /*FOR c from 0 to array_size*/
7. /*FOR d from c to array_size*/
8. /*Swap array[d] with array[d+1] if array[d]<array[d+1]*/
9. /*judge determines who wins*/
10. /*Initialize judge = -1 , Initialize i =0*/
11. /*WHILE i less than n and i less than m*/
12. /*IF array_1[i] > array_2[i]*/
13. /*Set judge = 0 and break*/ /*case where player 1 wins*/
14. /*ELSE if array_1[i] < array_2[i]*/
15. /*set judge = 1 and break*/ /*case where player 2 wins*/
16. /*ELSE judge = -1 and increment i*//*case where its a draw*/
17. /*when while loop is over*/
18. /*IF judge is -1 and i <n and i>=m
19. judge = 0*/
20. /*ELSE IF judge is -1 and i <n and i>=m*/
21. /*Set judge = 1*/
22. /*IF judge = 0 output "Player 1 wins"*/
23. /*IF judge = 1 output "Player 2 wins"*/
24. /*IF judge = -1, output "Draw"*/
25. /*END*/
26.
27. #include <stdio.h>
28. /*Define function*/
29. void bubblesort(int array[], int n)
30. {
31. /*Initialize variables*/
32. int c,d,swap;
33. /* start at the next number after the current number and compare with every number */
34. for (c = 0 ; c < ( n - 1 ); c++)
35. {
36. for (d = 0 ; d < n - c - 1; d++)/*Compare with every number */
37. {
38. if (array[d] < array[d+1])/* When the highest number is found */
39. {
40. swap = array[d];
41. array[d] = array[d+1];    /* Swap the poistion of the highest number found with the current number*/
42. array[d+1] = swap;
43. }
44. }
45. }
46. }
47.
48. int main(void)       /*[10] = array of 10 intergers*/
49. {
50. int array[10], n, c, d, swap;
51.
52. scanf("%d", &n);         /*This section is when player 1 enters number of cards up to 10*/
53. for (c = 0; c < n; c++)
54. scanf("%d", &array[c]);
55. bubblesort(array,n);/*Sorting for player 1 starts here*/
56.
57.
58.
59.
60.
61. int array2[10],m;
62. scanf("%d", &m);
63. for (c = 0; c < m; c++)
64. scanf("%d", &array2[c]);
65. bubblesort(array2,m); /*Sorting for player 2 starts here*/
66.
67.
68. /*Initialize variables e.g. judgement=-1*/
69. int judge = -1;
70. int i=0;
71. /*code for judgement of players*/
72. while(i<n && i<m) /* && means if the values are both not 0*/
73. {
74. if(array[i]>array2[i])
75. {
76. judge = 0;
77. break; /*Break statement is encountered inside a loop, the loop is immediately terminated*/
78. }
79. else if(array[i]<array2[i])
80. {
81. judge=1;
82. break;
83. }
84. i++;
85.
86. }
87. if(judge==-1 && i<n && i>=m)
88. judge = 0;
89. else if(judge==-1 && i<m && i>=n)
90. judge = 1;
91.
92. /*Displaying results*/ /*== means equal to*/
93. if(judge==-1)
94. {
95. printf("Draw");
96. }
97. else if(judge == 0)
98. {
99. printf("Player 1 wins");
100. }
101. else if(judge == 1)
102. {
103. printf("Player 2 wins");
104. }
105. return 0;
106. }