1
UNIT II
Conditional Control -Statements :Simple if, if...else - Conditional Statements : else if and nested if -
Conditional Statements : Switch case - Unconditional Control Statements : break, continue, goto -
Looping Control Statements:for, while, do..while - Looping Control Statements: nested for, nested
while - Introduction to Arrays -One Dimensional (1D) Array Declaration and initialization -
Accessing, Indexing and operations with 1D Arrays - Array Programs – 1D - Initializing and Accessing
2D Array, Array Programs – 2D - Pointer and address-of operators -Pointer Declaration and
dereferencing, Void Pointers, Null pointers Pointer based Array manipulation
Decision Making and Branching
C language provides the following conditional statements.
1. If statement.
2. IF …. Else statement.
3. Nested if …. Statement is also called as If …. Else ladder.
4. Switch case statement.
1. If statement.
The If is a statement is
decision making statement. To test
logically the condition is true or false.
Syntax:
if(true condition is true)
{
True statement;
}
Properties of an If statement.
1. if the condition is true ,then the simple statement are executed.
2. if condition is false ,it does not do any thing.
3. if a compound structure is provided, it must be enclosed in opening and closing
braces.
The program use of IF statement .
#include<stdio.h>
void main()
{
int i;
printf(“enter the number less than 10..”);
scanf(“%d”,&i);
if(i<=10)
{
printf(“%d”,i);
21CSS101J-PPS
, 2
printf(“\n the entered number %d is less than 10”,i);
}
}
Output:
Enter the number less than 10…5
The entered number 5 is less than 10.
2. If –Else Statement.
It is basically two way decision making statement. When condition
is true and execute some other statement, when the condition is false execute some of
the statement
Syntax:
if(condition)
{
true statement;
}
else
{
false statement;
}
Example program for if…else (Given number is odd or even)
#include<stdio.h>
#include<conio.h>
void main()
{
int num , rem;
clrscr();
printf(“enter the number”);
scanf(“%d”,&num);
rem=num%2;
if(rem==0)
printf(“the number is even”);
else
printf(“thenumber is odd”);
getch();
}
Output:
Enter the number: 80;
21CSS101J-PPS
, 3
The number is even.
3.Nested if-else statement.
When series of if-else statement are occurred in program. That is if else statement in another
if else statement.
Syntax:
if(condition 1)
{
if(condition 2)
{
true statement;2
}
else
{
false statement2
}
else
{
false statement 1;
}
}
4. If Else ladder statement
● if else statement in another else statement.
Syntax:
if(condition 1)
{
Statement 1;
}
else if(condition 2)
{
Statement 2;
}
else if condition 3)
{
Statement 3;
}
else
{
default statement;
}
21CSS101J-PPS
UNIT II
Conditional Control -Statements :Simple if, if...else - Conditional Statements : else if and nested if -
Conditional Statements : Switch case - Unconditional Control Statements : break, continue, goto -
Looping Control Statements:for, while, do..while - Looping Control Statements: nested for, nested
while - Introduction to Arrays -One Dimensional (1D) Array Declaration and initialization -
Accessing, Indexing and operations with 1D Arrays - Array Programs – 1D - Initializing and Accessing
2D Array, Array Programs – 2D - Pointer and address-of operators -Pointer Declaration and
dereferencing, Void Pointers, Null pointers Pointer based Array manipulation
Decision Making and Branching
C language provides the following conditional statements.
1. If statement.
2. IF …. Else statement.
3. Nested if …. Statement is also called as If …. Else ladder.
4. Switch case statement.
1. If statement.
The If is a statement is
decision making statement. To test
logically the condition is true or false.
Syntax:
if(true condition is true)
{
True statement;
}
Properties of an If statement.
1. if the condition is true ,then the simple statement are executed.
2. if condition is false ,it does not do any thing.
3. if a compound structure is provided, it must be enclosed in opening and closing
braces.
The program use of IF statement .
#include<stdio.h>
void main()
{
int i;
printf(“enter the number less than 10..”);
scanf(“%d”,&i);
if(i<=10)
{
printf(“%d”,i);
21CSS101J-PPS
, 2
printf(“\n the entered number %d is less than 10”,i);
}
}
Output:
Enter the number less than 10…5
The entered number 5 is less than 10.
2. If –Else Statement.
It is basically two way decision making statement. When condition
is true and execute some other statement, when the condition is false execute some of
the statement
Syntax:
if(condition)
{
true statement;
}
else
{
false statement;
}
Example program for if…else (Given number is odd or even)
#include<stdio.h>
#include<conio.h>
void main()
{
int num , rem;
clrscr();
printf(“enter the number”);
scanf(“%d”,&num);
rem=num%2;
if(rem==0)
printf(“the number is even”);
else
printf(“thenumber is odd”);
getch();
}
Output:
Enter the number: 80;
21CSS101J-PPS
, 3
The number is even.
3.Nested if-else statement.
When series of if-else statement are occurred in program. That is if else statement in another
if else statement.
Syntax:
if(condition 1)
{
if(condition 2)
{
true statement;2
}
else
{
false statement2
}
else
{
false statement 1;
}
}
4. If Else ladder statement
● if else statement in another else statement.
Syntax:
if(condition 1)
{
Statement 1;
}
else if(condition 2)
{
Statement 2;
}
else if condition 3)
{
Statement 3;
}
else
{
default statement;
}
21CSS101J-PPS