Advertisement
Guest User

evilzone

a guest
May 14th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define nl printf("\n")
  5. void game_rules();
  6. int generate_random(int min, int max);
  7. int show_result(int array1[],int array2[]);
  8. int coparation(int array1[], int array2[]);
  9. int main(int argc, char *argv[])
  10. {
  11.     srand(time(NULL));
  12.     int compare,i;
  13.     int A[10];
  14.     int B[10];
  15.     int C[10];
  16.   game_rules();
  17.   nl;
  18.   for(i = 0; i < 3; i++) {
  19.   A[i] = generate_random(0,9);
  20. }
  21.   puts("Enter 3 numbers from  0-9.");
  22.   for (i = 0; i < 3 ; i++){
  23.   scanf("%d",&B[i]);
  24. }
  25. nl;
  26. puts("Cheating numbers:");
  27. for (i = 0; i <3 ;i++)
  28. printf("+%d\n", A[i]);
  29.   printf("Total sum is: %d. Which numbers computer imagined?\n",show_result(A,B));
  30.   for(i = 0; i != 3 ; i++){
  31.   scanf("%d", &C[i]);
  32. }
  33. compare = compare(A,C);
  34.  
  35. switch(compare){
  36. case 1:
  37. puts("You scored one number!"); break;
  38. case 2:
  39. puts("You scored 2 numbers!"); break;
  40. case 3:
  41. puts("You scored 3 numbers!");break;
  42. default:
  43. puts("Imate nula pogodaka!"); break;
  44.  
  45. }
  46.  printf("Computer imagined this numbers :\n");
  47.  for(i = 0; i < 3 ; i++)
  48.  printf("%d\n", A[i]);
  49.   system("PAUSE");
  50.   return 0;
  51.      }
  52. void game_rules() {
  53. puts("Dobrodosli u igru 'Pogodi broj' . Pravila igre su: \n 1. Unosite 3 brojeva. \n 2. Pogadjate koja je 3 brojeva zamislio racunar.");
  54. puts(" 3. Imajte u vidu da racunar zamislja redom x,y,z brojeve, a vi unosite redom a,b,c brojeve. ");    
  55. puts(" 4. Nakon toga dobijate jedan broj u ovakvom obliku: ax + by + cz = r \n 5. Pogadjate brojeve x,y,c na osnovu zbira.");
  56.      }
  57. int generate_random(int min, int max)
  58. {
  59.    int random = rand() % ((max - min) + 1);
  60.    return random;
  61. }
  62. int show_result(int array1[],int array2[]) {
  63.  int x,y,z,result;
  64.  x = array1[0] * array2[0];
  65.  y = array1[1] * array2[1];
  66.  z = array1[2] * array2[2];
  67.  result = x + y + z;
  68.  return result;
  69. }
  70. int komparacija1(int array1[],int array2[]) {
  71. int i,j,case,case2,sum = 0;
  72. for(i = 0;i <1 ;i++)
  73.       for(j = 0; j< 3 ;j++) {
  74.       if (array2[i] == array1[j]) {
  75.       sum += 1;
  76.       case = j;
  77.       j +=2 ;
  78.            }
  79.       }
  80. for(i = 1;i <2 ;i++)
  81.       for(j = 0; j< 3 ;j++) {
  82.       if ((case == 0) && (j == 0)) j += 1;
  83.       if ((case == 1) && (j == 1)) j += 1;
  84.       if ((case == 2) && (j == 2)) j += 1;
  85.       if (array2[i] == array1[j]) {
  86.       sum += 1;
  87.       case2 = j;
  88.       j +=1 ;
  89.            }
  90.       }
  91. for(i = 2;i <3 ;i++)
  92.       if ( ((case == 0) || (case2 == 1)) && (j == 0) ) j += 2;
  93.       if ( ((case == 0) || (case2 == 2)) && (j == 0) ) j += 1;
  94.       if ( ((case == 1) || (case2 == 0)) && (j == 0) ) j += 2;
  95.       if ( ((case == 2) || (case2 == 0)) && (j == 0) ) j += 1;
  96.            
  97.       for(j = 0; j< 3 ;j++) {
  98.       if (array2[i] == array1[j]) {
  99.       sum += 1;
  100.            }
  101. if ( ((case == 0) || (case2 == 2)) && (j == 1) ) j += 2;
  102. if ( ((case == 2) || (case2 == 0)) && (j == 1) ) j += 2;
  103. if ( ((case == 1) || (case2 == 2)) && (j == 0) ) j += 3;
  104. if ( ((case == 1) || (case2 == 2)) && (j == 0) ) j += 3;
  105.       }
  106.       return sum;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement