luc100.c (1157B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Determine if an animal is Carnivore/Herbivore and its type (Canine, Feline, Cetacean, Marsupial) based on bits in an integer. 9 */ 10 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(b) */ 11 12 /* This file is auto-generated by a bot. */ 13 /* This code is not compiled; it is for reference only. */ 14 15 16 #include <stdio.h> 17 #include <stdlib.h> 18 19 struct animal 20 { 21 char name[30]; 22 int type; 23 }; 24 25 int main() 26 { 27 struct animal a = {"OCELOT", 18}; 28 int type = a.type; 29 30 printf("Animal: %s\n", a.name); 31 32 // Check Bit 4 for Diet (Assuming 1=Carnivore, 0=Herbivore based on context) 33 if (type & (1 << 4)) 34 printf("Diet: Carnivore\n"); 35 else 36 printf("Diet: Herbivore\n"); 37 38 // Check Bits 0-3 for Family 39 printf("Family: "); 40 if (type & (1 << 0)) printf("Canine "); 41 if (type & (1 << 1)) printf("Feline "); 42 if (type & (1 << 2)) printf("Cetacean "); 43 if (type & (1 << 3)) printf("Marsupial "); 44 printf("\n"); 45 46 return 0; 47 }