Вы находитесь на странице: 1из 13

Operator Meaning

== Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
!= Not equal to
7/25/2014 2
(also known as block)
Group of statements enclosed by braces, namely,
{ and }
The individual statements enclosed by braces are
executed in the order in which they appear
The general form of the compound statement is
{ S1;
S2;
.
.
Sn;}
7/25/2014 3
if statement
if else statement
Conditional operators
switch statement
goto statement



7/25/2014 4
The general form of the if statement as
follows
if( expresson )
statement;
Eg: if(a<10)
printf(Best of luck);

7/25/2014 5
The statement if(a>b) largest=a; is known as a conditional
statement
The general conditional statement is

if (logical expression)
{ S1t;
S2t;
.
.
Snt;}
else
{ S1e;
S2e;
.
.
Sme;}

7/25/2014 6
In the above general form if the logical
expression true then the compound
statement {S1t;S2t;;Snt;} is executed and
control jumps to the next statement following
the if statement. Thus the compound
statement following else is ignored
If the logical expression is false then the
compound statement appearing first is
ignored and the compound statement
{S1e;S2e;;Sme;} following else is executed
7/25/2014 7
if (logical expression)
{ S1t;
S2t:


Snt;}
In the above statement if the logical expression is
true then the compound statement
{S1t;S2t:;Snt;} is executed.
If the logical expression is false then the control
jumps to the statement following the right braces
ignoring the compound statement

7/25/2014 8
If we write an entire if-else construct within
either the body of the if statement or the
body of the else statement.
This is called nesting of ifs
7/25/2014 9
#include<stdio.h>
main()
{
int i;
printf(enter either 1 or 2);
scanf(%d,&i);
If(i==1)
printf(success);
else
{
if(i==2)
printf(failure);
else
printf(sorry it is a wrong number);
}
}
7/25/2014 10
To pick the largest of 3 numbers

7/25/2014 11
#include<stdio.h>
main()
{
int a,b,c;
scanf(%d %d %d,&a, &b, &c);
printf(a=%d, b=%d, c=%d\n, a, b, c);
if(a>b)
{
if(a>c)
printf(a=%d\n, a);
else
printf(c=%d\n, c);
}
else
{
if(b>c)
printf(b=%d\n, b);
else
printf(c=%d\n, c);
}
}


7/25/2014 12
#include<stdio.h>
main()
{
int a,b,c, big;
scanf(%d %d %d,&a, &b, &c);
printf(a=%d, b=%d, c=%d\n, a, b, c);
big=a;
if(b>big)
big=b;
if(c>big)
big=c;
print(the largest number is %d, big);
}

7/25/2014 13

Вам также может понравиться