Swap
using third variable
a,bàinput a=6 b=5
t=a; t=6
a=b; a=5
b=t; b=6
a,bàoutput
Swap
without using third variable
a,bàinput a=3 b=8
a=a+b; a=11
b=a-b; b=11-8=>
b=3
a=a-b; a=11-3=>
a=8
Decision Control
Structures
Simple
if
If
(condition)
{
//PROCESSING STATEMENTS
}
Condition:
true / false
Conditional operator or relational
operator
> <
>=
<= != ==
e.g1
a=8, b=5
a>b t
a<b f
a>=b t
a!=b t
a==b
f
e.g2
a=40 b=40
a>b
f
a<b f
a==b t
a!=b
f
a>=b t
a<=b t
if else
if
(condition)
{
//PROCESSING
STATEMENTS
}
else
{
//PROCESSING
STATEMENTS
}
Take any Number
& Find which number is +ve or -ve.
nàinput
n>0 printf(“positive number”) else printf(“negative”)
No comments:
Post a Comment