Structures and Pointers – Arithmetic – Problem #2

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

Problem Statement

A country has ‘n’ number of zoos, where each zoo has a certain number of tigers, lions and elephants. It is required to perform some analysis on the number of animals within each zoo of the country. Declare a structure named ‘zoo’ that contains three integer type values, each to hold the number of tigers, lions and elephants within that zoo. Also declare an array ‘zoo count[ ]’ of size n, which is an array of structure of the type ‘zoo’ that holds the information about all the n zoos of the country. Take, ‘n’ as input from the keyboard and fill out the array ‘zoo count[ ]’ taking the number of tigers, lions and elephants of each zoo as user input. Note that zoo count[0] holds the number of animals (tigers, lions and elephants) of the first zoo, zoo count[1] holds the number of animals of the second zoo and so on. Also as zoo count[ ] is an array of structures, each element of the array is actually a structure of type ‘zoo’. After you have taken input, perform the following three operations and print the result. • Print the total number of tigers in all the zoos within the county. • Print all the zoo numbers (i.e., the index of the zoo count[ ] array) that contains less than or equal to 6 lions. • Print the zoo numbers (i.e., the indices of the zoo count[ ] array) according to the increasing order of the number of elephants contained within each zoo. Example: Input: Enter ‘n’ : 3 Enter for zoo 1 Tigers - 4 Lions - 3 Elephants - 10 Enter for zoo 2 Tigers - 2 Lions - 8 Elephants - 5 Enter for zoo 3 Tigers - 8 Lions - 5 Elephants - 4 Output: Total number of tigers = 14 Zoos with lions less than or equal to 6 = 1, 3 Zoo indices as per increasing order of elephants = 3, 2, 1

Back to Lab Problems
Structures and Pointers/Arithmetic/Problem #2

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #2

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.