Solving problems in the program for the serial structure

Suppose you are asked to make the algorithm and program for calculating area and volume of a beam. The area of the beam formula is area = (2 * p * l) + (2 * p * t) + (2 * l * t), while the volume of the beam is = p * l * t.
Note:
p = length
l = width
t = high

The algorithm of the problem is:
1. Insert length
2. Enter the width
3. Enter height
4. Size = (2 * length * width) + (2 * length * height) + (2 * width * height)
5. volume = length * width * height
6. Display area
7. Show volume


Description of the algorithm above is:
on the first line, second and third, you are prompted to enter input that is related to the beam length, width and height. The length of the beam is stored in variable length, the width of the beam is stored in the variable beam width and height are stored in the variable high. Meanwhile, in the fourth and fifth rows, you are prompted to enter a formula to find area and volume of the beam, ie area = (2 * length * width) + (2 * length * height) + (2 * width * height) and volume = length * width * high. For the broad beam is stored in the variable beam area and volume stored in the variable volume. And the sixth and seventh lines are the result of the calculation of input and process variable input is entered and will be displayed area and volume of the beams.



mplementation of the above algorithm in the program:

/*----------------------------------------*/
/ * program: balok.cpp * /
/*----------------------------------------*/
# include <stdio.h>

main ()
{
     int length, width, height, area, volume;
     printf ("enter the length:"); scanf ("% d", & length);
     printf ("enter the width:"); scanf ("% d", & width);
     printf ("enter the height:"); scanf ("% d", & height);
     area = (2 * length * width) + (2 * length * height) + (2 * width * height);
     volume = length * width * height;
     printf ("finished width is:% d \ n", size);
     printf ("so its volume is:% d \ n", volume);
}

Leave reply

Back to Top