Sunday, December 6, 2009

1.10 STATEMENTS

A statement causes the computer to carry out some action. There are three different classes of statements in C. They are expression statements, compound statements and control statements.

Several statements are shown below

a=3;---> expression statement
c=a+b;---> expression statement
++i;--->expression statement
printf(“area=%f”,area);-->expression statement


{
pi=3.14;
circumference=2*pi*radius;
area=pi*radius*radius;

}

This is a compound statement, which consists of three assignment type expression statements. Note that the compound statement does not end with a semicolon.

The following control statement creates a conditional loop in which several actions are executed repeatedly, until some particular condition is satisfied.

while(count<=n) { printf(“x=”); scanf(“%f”, &x); sum=sum+x; ++count; } This control statement contains a compound statement, which in turn contains four expression statements. The compound statement will continue to be executed as long as the value of count does not exceed the value of n.Note that the count increase in value during each pass through the loop.

No comments:

Post a Comment