Advertisement
TawratNibir

Guessing game

Jan 10th, 2025
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include<time.h>
  4. #include<stdlib.h>
  5. int main()
  6. {
  7.     int a[8]={2};
  8.     for(int i=0;i<8;i++) a[i]=2;
  9.     srand(time(NULL));
  10.     int x = rand()%8 + 1;
  11.     a[x-1] = 1;
  12.     int i=0, j=0, k=0;
  13.     int y1, y2, s1, s2;
  14.     while(i<2) {
  15.         s1=s2=0;
  16.         printf("\nTry %d :\n", i+1);
  17.         printf("How many items in left side? : ");
  18.         scanf("%d", &y1);
  19.         for(int i=0;i<y1;i++) {
  20.             scanf("%d", &y2);
  21.             s1+=a[y2-1];
  22.         }
  23.         printf("How many items in right side? : ");
  24.         scanf("%d", &y1);
  25.         for(int i=0;i<y1;i++) {
  26.             scanf("%d", &y2);
  27.             s2+=a[y2-1];
  28.         }
  29.         if(s1==s2) {
  30.             printf("They are equal!");
  31.         }
  32.         else{
  33.             printf("The weights are: %d and %d. They are not equal.", s1, s2);
  34.         }
  35.         i++;
  36.     }
  37.     printf("\nEnter your guess: ");
  38.     scanf("%d", &k);
  39.     if(k==x) printf("\nYou are absolutely right!");
  40.     else printf("\nBetter luck next time! :V");
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement