/*************************************** ***********************
* *** AUTHER: liuyongshui
* ****** DATE: 2013 \ 4 \ 7
* ** LANGUAGE: C
* ** QUESTION: write a program using a struct to obtain the volume and surface area of the three Bulk columns.
**************************************** *****************/
# Include <stdio. h>
Struct bulk
{
Float length;
Float width;
Float heigth;
};
Void volume (struct bulk B []); // statement of the original function
Void areas (struct bulk B []);
Int main ()
{
Int I;
Struct bulk BULK [3];
For (I = 0; I <3; I ++)
{
Printf ("the length, width, and height of the % d cuboid: \ n", I + 1 );
Scanf ("% f", & BULK [I]. length, & BULK [I]. width, & BULK [I]. heigth );
}
Volume (BULK); // transfer the struct
Areas (BULK );
Return 0;
}
// Function Definition
Void volume (struct bulk B []) // calculates the volume
{
Int I;
For (I = 0; I <3; I ++)
{
Printf ("the volume of the % d cube % f \ n", I + 1, B [I]. length * B [I]. width * B [I]. heigth );
}
}
Void areas (struct bulk B []) // calculate the over-surface area
{
Int I;
For (I = 0; I <3; I ++)
{
Printf ("% d cube surface area % f \ n", I + 1, 2 * (B [I]. length * B [I]. width +
B [I]. heigth * B [I]. width +
B [I]. length * B [I]. heigth ));
}
}