Question 25: write a program using a struct to obtain the volume and surface area of the three Bulk.

Source: Internet
Author: User

/*************************************** ***********************
* *** 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 ));
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.