prev


Assigned Values For Variables

4.Volume of cylinder (19.6.2009)

/*
Program# 4
date : 10-12-2008
Volume of cyclinder
*/

#include <stdio.h>
main(){
float r,p,c;
r=5.0;
p=3.14;
h=6.0;
c=p*(r*r)*h;
printf("\nVolume of cyclinder : %f\n",c);
}

output:
Volume of cyclinder : 471.000031

Things to note:
The formula is pi r^2 h, the parentheses is used here to avoid the confusion. It is a good practise to use parentheses in a long expression, the expression becomes more understandable. According to hierarchy of operations, parentheses is evaluated first, if there are more than one set of parentheses, the innermost would be performed first, followed by the second innermost and so on.

stepwise evaluation of the expression is shown below.

c = 3.14*(5.0*5.0)*6.0

Expression Operation
c = 3.14*(25)*6.0 (*)
c = 78.5*6.0 *
c = 471.0 *
next
blog comments powered by Disqus