hot post

if-else statement in c programming || Decision Control in C Part 2

if-else statement in c programming || Decision Control in C Part 2


if-else statement in c programming

if-else statement in c programming- Today, we will learn about the if-else statement by moving this C programming language tutorial. Before that it is necessary to know about "use of if statement in c". For this you have to click on use of if statement in c and you reach on my previous post where i have covered all  about 'if statement in decision control'.

Then let's start today's topic which is 'if-else statement'.

What is 'if-else statement'

For this we have to know the syntax of 'if-else statement'.

syntax of 'if-else statement'

if(boolean expression)
{
line 1;
line 2;
......
}
else
{
line 1;
line 2;
.....
}

A boolean expression is one whose value is true or false. If the value of boolean expression is true then only statement will execute. Like this, we will keep moving forward. Wherever we get the value of boolean expression true only the statement related to it will be executed, no one else. If a boolean expression is not true, then the statement inside the else will be executed.

 Let us understand this by some examples.

Example. 1

lets take our previous example where we will find the number is positive or no positive. In the previous part we use if but now we use if-else statement.


if-else statement in c programming || Decision Control in C Part 2


Output
if you enter any  number which is greater then 0 then it will show 'the number is positive'
if you enter any  number which is less then 0 then it will show 'the number is non positive'

Example. 2

In this program, we will find the student is pass or fail.

if-else statement in c programming || Decision Control in C Part 2 

Output
if you enter any  number which is greater then 31 then it will show 'you are pass'.
if you enter any  number which is less then 31 then it will show 'you are fail'.


Example. 3

In this program, you can find the number is less then 100 or greater then 100.

if-else statement in c programming || Decision Control in C Part 2

Output
if you enter any  number which is greater then 100 then it will show 'the number is greater then 100'.
if you enter any  number which is less then 100 then it will show 'the number is less then 100'.


You can also try another examples and learn the use of if-else statement very well
 thanks for reading this post
also read


Post a Comment

0 Comments