The idea of programming might sound like a frightening task, but don’t worry. We designed this blog so that you can get your feet wet without stepping into the deeper complexities of the programming.
This Blog is dedicated to all those people who want to learn the most basic but important Programming Language'C Programming'.
If done step wise C language is easy and fun to learn.
So lets get started.
Start reading from the First Post to understand C programming.You may read a desired topic from the labels.
Press Ctrl+D to add this page to your Favourites/Bookmarks for further reference.
Note:Your comments,queries and suggestions are welcome.Feel free to post them in the the comment boxes available after every post.

Search C Programs,Compilers,etc.

Saturday, June 7, 2008

The if-else Statement

The if-else Statement

As described in earlier post,the if statement will execute a single statement, or a group of statements, when the expression following if evaluates to true.But it does nothing when the expression evaluates to false.
In case, we want to execute one group of statements if the expression evaluates to true and another group of
statements if the expression evaluates to false,we need to use the If-else statement.
The syntax of If-else statement is as follows;
if(condition)
{

statement;

}
else
{

statement2;

}

If the condition 1 is evaluated true,then statement1 will execute else statement2 will be executed.
A simple example is;

if(a=2500 )
{
hra = 1200;
da = basic * 0.5 ;pt=150;
}
else
{
hra = basic*0.1 ;
da = basic * 25.01 / 100 ;
}
gs = basic + hra + da ;
net=gs-pt;
printf ( "Net salary = Rs. %f", net ) ;
}

0 comments: