Saturday 22 February 2020

Control statements in C Programming Language - tccicomputercoaching.com


Some time we need to take decision depending on some condition. Result will be true or false. If condition fulfil then result is true otherwise false.



For Example, student is Pass or Fail is dependent on their Percentage. Suppose Criteria is 50 %. So, student getting Percentage above 50 % then he or she is Pass otherwise fail.

There are 3 types of control statements :

Let us see one by one.

1. if -else

if(condn)

{

st.1;

}

else

{

st.2;

}

if(total>150)

{

printf("pass");

}

else

{

printf("fail");

}

---------------------------------------------------------------

example,

if(a%2==0)

{

printf("a is even");

}

else

{

printf("a is odd");

}

=================================================

2 .nested if-else

if(condn)

{

if(cond2)

{

st.1;

}

else

{

st.2;

}

}

else

{

if(cond3)

{

st.3;

}

else

{

st.4;

}

}

-------------------------------------------------------------------------

example:

if(a>b)

{

if(a>c)

{

"a";

}

else

{

"c";

}

}

else

{

if(b>c)

{

"b";

}

else

{

"c";

}

}

=================================

3. else-if ladder

if(c.1)

{

st.1;

}

else if(c.2)

{

st.2;

}

else if(c.3)

{

st.3;

}

else if(c.4)

{

st.4;

}

else

{

st.5;

}

-------------------------------------------------------------------------------------

example.

if(p>=70)

{

"A";

}

else if(p>=60)

{

"B";

}

else if(p>==50)

{

"C";

}

else if(p>==40)

{

"D";

}

else

{

"fail";

}

For more information about control statements in C Programming Language

Call us @ 9825618292

Visit us @ http://tccicomputercoaching.com/

No comments:

Post a Comment