prev


Assigned Values For Variables

2.Area of circle with Operator Precedence (17.6.2009)

/*
Program# 2
date : 10-12-2008
Area of circle
*/

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

output:
Area of circle : 78.5

Things to note:
In this program,area of circle is calculated using the given values.There are two multiplication operators found in a single expression, they are evaluated from left to right, that is first (p*r) is evaluated and the result is multiplied again with r,which is to say p*r*r is evalauted as (p*r)*r.Remember ( ) has highest precedence.The hierarchy of commonly used operators is shown below.

Priority Operators Description
1st * / % multiplication, division, modular division
2nd + - addition, subtraction
3rd = assignment


next
blog comments powered by Disqus