Advertisement
abdulalim-swe

Cake Sharing Conundrum

Sep 17th, 2024
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     long long N, K;
  5.  
  6.     // Input the number of cakes (N) and the number of guests (K)
  7.     scanf("%lld %lld", &N, &K);
  8.  
  9.     // Case 1: No guests (K == 0)
  10.     if (K == 0) {
  11.         printf("Sorry, it's not possible to share the cakes equally!\n");
  12.     }
  13.     // Case 2: More guests than cakes (N < K)
  14.     else if (N < K) {
  15.         printf("Sorry, it's not possible to share the cakes equally!\n");
  16.     }
  17.     // Case 3: Check if cakes can be evenly distributed (N % K == 0)
  18.     else if (N % K == 0) {
  19.         printf("%lld\n", N / K);
  20.     }
  21.     // Case 4: Cakes cannot be distributed equally (N % K != 0)
  22.     else {
  23.         printf("Sorry, it's not possible to share the cakes equally!\n");
  24.     }
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement