FPL (1)
FPL (1)
Program-FPL Syllabus
Implementation (2024 pattern)
UNIT 2 Operators and Expressions
&
UNIT 3 Decision Control
Statement
CO PO Justification
Apply the knowledge of basics of programming and
PO1 problem solving to choose most appropriate techniques to
solve the problem
PO2 Identify and analyze the method of problem solving
CO2 PO3 Design and formulate algorithm, flowchart for the problem
statement
PO5 Develop C program using modern tools.
Build ability to learn advanced and latest feature of C
PO12 programming to solve problem
Introduction
• Operators are used to perform operations
on variables and values.
• Operators are symbols, such as +, –, =, >,
and <, that perform certain mathematical
or logical operation to manipulate data
values and produce a result based on some
rules.
• An operator manipulates the data values
called operands.
Types of Operator
Types of Operator Description
Increment and Decrement Either increment or decrement the value of the variable
Operators by one
Conditional Operators Conditional operators return one value if condition is true
and returns another value is condition is false
Bitwise Operators Perform bit wise operation on given two variables.
• x = a * b - c;
• y = b / c * a;
• z = a - b / c + d;
• When these statements are used in a program, the variables x, y, z, a, b, c and d
must be defined before used
• in the expressions.
• The blank space around an operator is optional and adds only to improve
readability.
• https://tutorialwing.com/operators-in-c-pr
ogramming-with-examples/
UNIT 3
Decision Control Statements
CO PO Justification
Apply the knowledge of basics of programming and
PO1 problem solving to choose most appropriate techniques to
solve the problem
PO2 Identify and analyze the method of problem solving
CO3 PO3 Design and formulate algorithm, flowchart for the problem
statement
PO5 Develop C program using modern tools.
Build ability to learn advanced and latest feature of C
PO12 programming to solve problem
Decision Control Statements
• The control flow statements (FIGURE 3.1) in C
Programming Language are
• 1. Decision Control Flow Statements:
Depending on whether a condition is True or False,
the decision structure may skip the execution of an
entire block of statements or even execute one
block of statements instead of other (if, if…else and
if…elif…else).
• 2. Loop Control Flow Statements: This is a
control structure that allows the execution of a
block of statements multiple times until a loop
termination condition is met (for loop and while
loop). Loop Control Flow Statements are also called
Repetition statements or Iteration statements.
Decision Control Statements
• Decision Control statement is divided into
two parts
▫ Selection/Conditional Branching
If For
Nested if
Stateme While Loop Loop
Condition
nt
If-else If-elif-if
Statement Statement
• Decision making is the most important aspect of almost all
the programming languages.
• As the name implies, decision making allows us to run a
particular block of code for a particular decision.
• Here, the decisions are made on the validity of the particular
conditions. Condition checking is the backbone of decision
making.
• In C, decision making is performed by the following
statements.
Statement Description
• Syntax:.
if condition :
Statement 1
Statement 2 Flowchart
Statement 3
Example 1 Example 2
• #include<stdio.h>
• #include<stdio.h>
• #include<conio.h>
• #include<conio.h>
• Void main()
• Void main()
• {
• {
• int n;
• int marks;
• clrscr();
• clrscr();
• Printf(“ Enter any no.”);
• Printf(“enter the number”)
• Scanf(“%d”, &n);
• Scanf(“%d,&marks);
• if(n>=0)
• if (marks>=250)
• {
• {
• printf(“Enter no. is positive”);
• printf(“pass”);
• }
• }
• getch();
• getch()
• Output:
• Output:
Enter any no. 100
enter the number 256
Pass Enter no is positive
Write a C Program to Reads a Number and Prints a Message If It
Is Positive
The if-else statement
• The if-else statement provides an else
block combined with the if statement
which is executed in the false case of
the condition.
• If the condition is true, then the if-block
is executed. Otherwise, the else-block is
executed.
• Syntax:
▫if condition:
▫ #block of statements
▫else:
▫ #another block of statement
s (else-block) Flowchart
Example :
• Write a Program to check whether a person is eligible to vote or n
ot
.
• Write a Program to Find the Greater and smaller
of Two Numbers
• Write a program to find weather a given year is a
leaf year or not
• Write a program to find weather a given number i
s a even or odd
Nested If
• You can have if statements inside if statements, this
is called nested if statements.
• Any Number these statements can be nested inside
one another.
• Indentation is the only way to figure out the level of
nesting.
Example
• Write a C program using nested if print salar
y of employee
The if-elif-else statement
• The elif statement enables us to check multiple
conditions and execute the specific block of statements
depending upon the true condition among them.
• We can have any number of elif statements in our
program depending upon our need. However, using elif
is optional.
• The elif statement works like an if-else-if ladder
statement in C. It must be succeeded by an if statement.
If-elif-else
• Syntax:
if expression 1:
# block of statements
elif expression 2:
# block of statements
elif expression 3:
# block of statements
else:
# block of statements
Write a c program to
check tax pay on sala
ry Flowchart
Basic Loop Structure/ Iterative Statements
• C Loops
▫ C has two primitive loop commands:
● while loops
● for loops
• The flow of the programs written in any programming language is
sequential by default. Sometimes we may need to alter the flow of
the program. The execution of a specific code may need to be
repeated several numbers of times.
• For this purpose, The programming languages provide various
types of loops which are capable of repeating some specific code
several numbers of times. Consider the following diagram to
understand the working of a loop statement.
• Definition: Repeated execution of a set of statements is called
iteration.
Why we use loops in C?
• The looping simplifies the complex problems into the easy
ones.
• It enables us to alter the flow of the program so that instead
of writing the same code again and again, we can repeat the
same code for a finite number of times.
• For example, if we need to print the first 10 natural numbers
then, instead of using the print statement 10 times, we can
print inside a loop which runs up to 10 iterations.
Advantages of loops
• There are the following advantages of loops in C.
• It provides code re-usability.
• Using loops, we do not need to write the same code
again and again.
• Using loops, we can traverse over the elements of
data structures (array or linked lists).
The while Loop
• The while loop is also known as a pre-tested loop. In
general, a while loop allows a part of the code to be executed
as long as the given condition is true.
• It can be viewed as a repeating if statement. The while loop is
mostly used in the case where the number of iterations is not
known in advance.
• With the while loop we can execute a set of statements as
long as a condition is true.
• Syntax:
while expression:
statements 1
statement 2
statement 3
• Example:
• Write a c program to
compute the sum of t
he first 10 natural nu
mbers using for loop.
• Write a c program to
print multiplication t
able using for loop.
Program using while or for loop
• Write a C program using for loop to calculate facto
rial of a number.
• Write a C program using for loop to print all the nu
mbers from m-n thereby classifying them as even o
r odd.
• Write a C program to sum the series 1+1/2+1/3+1/
4….1/n
• Write a C program to calculate sum of cubes of nu
mbers from 1-n
• Write a C program to calculate sum of square of ev
en numbers
Nested for loop in C
• C allows us to nest any number of for loops inside a for loop.
The inner loop is executed n number of times for every iteration
of the outer loop. The syntax of the nested for loop in C is given
below.
C by E Balagurusamy
wamy
Thank You