2. CONTENTS
1 C
Header File and Main Function
Conditional Statements
If Condition
If-else Condition
2
3
4
5
6 If-else if Condition
3. 1
C
C was originally developed in the 1970s, by
Dennis Ritchie at Bell Telephone
Laboratories, Inc.
C is a High level , general –purpose
structured programming language.
Instructions of C consists of terms that are
very closely same to algebraic expressions,
consisting of certain English keywords such
as if, else, for ,do and while
5. 3
Header
filesThe files that are specified in the include
section is called as header file . These are
precompiled files that has some functions
defined in them . We can call those functions
in our program by supplying parameters
Header file is given an extension .h
C Source file is given an extension .c
6. 4
Main
function
This is the entry point of a program .When a file
is executed, the start point is the main function .
From main function the flow goes as per the
programmers choice . There may or may not be
other functions written by user in a program
Main function is compulsory for any c program
1
2
3
4
7. 5
Conditional Statements Are Used To Execute A
Set Of Statements On Some Conditions. It
Provides A Unit Of Block In Which We Can Either
One Statement Or More Than One Statement . If
The Given Condition Is True Then The Set Of
Statements Are Executed Otherwise Body Is
Skipped.
C supports two types of selection
statements :-
The if statement
The switch statement
Conditional
Statements
8. 6
If
Condition
It is conditional statement, which is used to
execute a set of statement on some
conditions. The condition must be of Boolean
type expression.
An expression, which returns only two value
either TRUE or FALSE, is known as Boolean
type expression.
Syntax:-
if (expression)
statement(s);
10. 8
If-else
ConditionIt Is Known As Double Blocked Conditional
Statements .It Means, It Has TRUE Parts As
Well As FALSE Part.
If The Given Condition Is True Then The True
Part Is Executed Otherwise False Part Is
Executed.
Syntax:-
if (expression)
statement(s);
[else statement(s);]
11. 9
Example
#include <stdio.h>
void main()
{
int num , res ;
printf(“Enter a number :”);
scanf(“%d”,&num);
res = num % 2;
if (res == 0)
printf(“Then number is Even”);
else
printf(“The number is Odd”);
}
12. 10
If-else if
Condition
The if...else statement executes two different
codes depending upon whether the test
expression is true or false. Sometimes, a choice
has to be made from more than 2 possibilities.
Syntax:-
if ( this logical expression is true )
statement ;
else if ( this logical expression is true
)
statement ;
else if ( this logical
expression is true )
statement ;
else