Decision Control in C Conditional tag

-- Leave a Comment
in c programming we need to control some decisions as if this comes true the program should do this else the program should do this. Today we will learn about all these.

If Statement

if statement is used when we want some part of program should be operated only if some conditinn is true. General form of if statement is if (Condition)
Do this;

if (a==b)
printf("a and b are equal");

In above program a and b are equal is displayed only when a are equal to b.

If else statement

if(a==b)
printf("a and b are equal");
else
printf("a and b are not equal");

If else if statement

if(a>80)
printf("Distionction");
else if (a>60 && a<80)
printf("First division");
else if(a<60 && a>40);
printf("Passed");
else
printf("Failed");

Nested if else

if()
{
if()
do this
else
do this
}
else if ()
{
if()
{
if()
do this
else
do this
}
else
do this
}
else
do this

The above is simple structure.

Next we will go to loop control structure do comment if you need help in some programs in your Lab assignment questions or class questions.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University, NCIT. Open Source Enthusiastic.

0 comments:

Post a Comment