+ 1

How this code work?

#include <stdio.h> typedef struct { int h; int w; int l; } box; int main() { box boxes[3] = {{2, 6, 8}, {4, 6, 6}, {2, 6, 9}}; int k, volume; for (k = 0; k < 3; k++) { volume = boxes[k].h*boxes[k].w*boxes[k].l; printf("box %d volume %d\n", k, volume); } return 0; }

8th May 2020, 10:07 AM
Lakshya Singhal
2 ответов
+ 1
Lakshya Singhal This program is to calculate and display volumes of boxes Here first define a structure named box contain three elements h,w,l Then in main we initialise an array of three In for loop it calculate the volume and prints as below: box 0 volume 96 box 1 volume 144 box 2 volume 108
8th May 2020, 10:26 AM
Bensen
0
It's a program that calculates the volume of each box you create, boxes are represented as structures. What's the part you can't understand? Be more specific and I'll try to help you.
8th May 2020, 10:26 AM
Alessandro Palazzolo
Alessandro Palazzolo - avatar