prev | Assigned Values For Variables 3.Volume of sphere (18.6.2009) /* Program# 3 date : 10-12-2008 Volume of sphere */ #include <stdio.h> main(){ float r,p,c; r=5.0; p=3.14; c=4.0/3.0*p*r*r; printf("\nVolume of sphere : %.2f\n",c); } output: Volume of sphere : 104.66 Things to note: 1. In the computation part, the real value are used (note 4.0 and 3.0). If integer value is used (4/3), then the output will be wrong. Since 4/3 produces result as 1. Because if both operands are int then result will be of type "int". 2. Both / and * operator same precedence so they are evaluated from left to right. stepwise evaluation of the expression is shown below. c = 4.0/3.0*3.14*5.0*5.0
|
next |