/*Calculating the height of a tree */ #include<stdio.h>
void main()
{ long shorty=0L; /*shorty's height in inches */ long lofty=0L; /*lofty'height in inches */ long feet=0L; /*A whole number of feet */ long inches=0L; /* A whole number of inches */ long shorty_to_lofty=0L; /* distance form shorty to lofty in iches */ long lofty_to_tree=0; /* distance form lofty to tree */ long tree_height=0; /* height of the tree in inches */ const long inches_per_foot=12L;
/* Get lofty's height */
printf("Enter lofty's height to the top of his/her head,in whole feet: "); scanf("%d",&feet); printf(" ........... and then inches: "); scanf("%d",&inches); lofty=feet*inches_per_foot+inches;
/*Get shorty's height up to his/her eyes*/ printf("Enter shorty's height up to his/her eyes,in whole feet: "); scanf("%d",&feet); printf(" ............ and then inches: "); scanf("%ld",&inches); shorty=feet*inches_per_foot+inches;
/*Get the distance from Shorty to lofty*/ printf("Enter the distance between Shorty and lofty,in whole feet: "); scanf("%ld",&feet); printf(" ............and then inches: "); scanf("%ld",&inches); shorty_to_lofty=feet*inches_per_foot+inches;
/* Get the distance from lofty to the tree*/ printf("Finally enter the distance to the tree to the nearest foot: "); scanf("%ld",&feet); lofty_to_tree=feet*inches_per_foot;
/*Calculate the height of the tree in inches */ tree_height=shorty+(shorty_to_lofty +lofty_to_tree)*(lofty-shorty)/shorty_to_lofty;
/*Display the result in feet and inches */ printf("The height of the tree is %ld feet and %ld inches.\n", tree_height/inches_per_foot,tree_height%inches_per_foot); getchar();