0% found this document useful (0 votes)
23 views48 pages

FPL (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views48 pages

FPL (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

One Day Faculty Orientation

Program-FPL Syllabus
Implementation (2024 pattern)
UNIT 2 Operators and Expressions
&
UNIT 3 Decision Control
Statement

Dr. Poonam Lambhate


Professor
SPPU BOS IT Member
Department of Computer Engineering
JSPM,JSCOE, Hadapsar, Pune
COURSE OUTCOME
CO CO DESCRIPTION
To Design algorithms for simple computational
CO1
problems.
To Use mathematical, Logical Operators and
CO2
Expressions.
To apply Control Flow structures for decision
CO3
making.
To design a solution using Arrays, Character and
CO4
String Arrays.
CO5 To Design and apply user defined functions.
To Apply structures in Problem solving using C programming
CO6
language.
UNIT 2
Operators and Expressions

Arithmetic Operators, Relational Operators,


Logical Operators, Assignment Operators,
Increment and Decrement Operators,
Conditional Operators, Bitwise Operators,
Operators and
II Special Operators.
Expressions:
Arithmetic Expressions, Evaluation of
Expressions, Precedence of Arithmetic
Operators, Operator Precedence and
Associativity, Mathematical Functions

CO2 To Use mathematical, Logical Operators and Expressions.


CO2 mapping with PO’s

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

Arithmetic Operators Perform Mathematical calculation like addition,


subtraction multiplication, division and modulus
Relational Operators Compare the values of two variable

Logical Operators Perform logical operations on the given two variable

Assignment Operators Assign the values for the variable in C programs

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.

Special Operators &, *, sizeof() and ternary operators


Arithmetic Operators
Operator Name Description Exampl Program
e
+ Addition Adds together x+y int main() {
int x = 5;
two values int y = 3;
printf("%d", x + y);
return 0;}

- Subtraction Subtracts one x-y int main() {


int x = 5;
value from int y = 3;
another printf("%d", x - y);
return 0;}

* Multiplication Multiplies two x*y int main() {


int x = 5;
values int y = 3;
printf("%d", x -*y);
return 0;}

/ Division Divides one x/y int main() {


int x = 5;
value by int y = 3;
another printf("%d", x -/y);
return 0;}

% Modulus Returns the x%y int main() {


int x = 5;
division int y = 3;
remainder printf("%d", x -%y);
return 0;
Program
• Write a program in C to implement all arithmetic operation on two
numbers.
• Program on Arithmetic
• Write a program in C to implement Relational Operators
• Program on Relational Operator
• Write a program in C to implement Logical Operators
• Program on Logical Operator
• Write a program in C to implement Assignment Operators.
• Program on Assignment operator
• Write a program in C to implement Increment and Decrement
Operators.
• Program on increment and decrement
• Write a program in C to implement Conditional Operators
• Program on Conditional Operator
• Write a program in C to implement Bitwise Operator
Program on Bitwise Operator
• Write a program in C to implement Special Operators
• Program on Special Operators
Arithmetic Expressions
• An arithmetic expression in c is a
combination of variables, constants, and
operators arranged as per the syntax of the
language.
• C can handle any complex mathematical
expressions.
• Examples of C expressions:
Algebraic C Expression
Expression
axb–c a*b–c
(m + n)(x + y) (m + n) * (x + y)
ab / c (a*b) / c
3x2 + 2x + 1 (3 * x * x) + (2 * x) + 1
x/y+c x/y+c
Evaluation of Expressions
• Expressions are evaluated using an assignment statement of the form:
• variable = expression;
• Variable is any valid C variable name.
• When the statement is encountered, the expression is evaluated first and the
result then replaces the previous
• value of the variable(on the left-hand-side).
• All variables used in the expression must be assigned values before evaluation is
attempted.
• Examples of Evaluation Statement:

• 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.

• Write a program in C to implement Arithmetic Expression


• Program on Arithmetic Expression
Precedence of Arithmetic Operators
• Each arithmetic operator in C has a precedence
associated with it. It is used to determine how an
expression involving more than one operator is
evaluated.
Operators Operations Order of Evaluation(Precedence)
() Parentheses Evaluated first. If the parentheses are nested, the
expression in the innermost pair is evaluated first. If there
are several pairs of parentheses “on the same level”
(i.e. ,not nested), they are evaluated left to right.
*/% Multiplication, Evaluated second. If there are several, they are
Division, Remainder evaluated left to right
+– Addition, Evaluated third. If there are several, they are evaluated
Substraction left to right
= Assignment Evaluated last

Example of Precedence of Arithmetic Operators in C


Operator Precedence and Associativity
• The operators of the same precedence are
evaluated either from left to right or from right
to left, depending on the level. This is known
as Associativity property of an operator.
• It is used when two operators of same
precedence appear in an expression.
• Example and Explanations
Mathematical Functions
• C Mathematical functions are predefined
functions which accept values and return the
result. To use mathematical functions, we have
to include math.h header file in our program.
• With the help of mathematical functions we can
easily solve a complex equation in our program,
for example, if we want to find the square root
of a number, then we can
use sqrt() mathematical function to find the
square root of a given number.
• Different Mathematical function and its informa
tion
More Practice Tutorial and Programs
on Operators

• https://tutorialwing.com/operators-in-c-pr
ogramming-with-examples/
UNIT 3
Decision Control Statements

Decision Simple If Statement, If-Else, Else-If,


1 Making and Switch Statement, Goto Statement
Branching:
Decision While Statement, Do-While, For
Making and Statement, Break and Continue
2
Looping:

Exemplar/ Design simple calculator and


Case Studies Generating a Calendar

CO3 To apply Control Flow structures for decision making.


CO3 mapping with PO’s

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

▫ Basic Loop Structure/ Iterative Statements/


Repetition statements
Decision Control Statements

Selection/Conditional Basic Loop Structure/


Branching Iterative Statements

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

If Statement The if statement is used to test a specific


condition. If the condition is true, a block
of code (if-block) will be executed.
If - else The if-else statement is similar to if
Statement statement except the fact that, it also
provides the block of the code for the false
case of the condition to be checked. If the
condition provided in the if statement is
false, then the else statement will be
executed.
Nested if Nested if statements enable us to use if ?
Statement else statement inside an outer if statement.
The if statement
• The if statement is used to test a
particular condition and if the
condition is true, it executes a
block of code known as if-block.
The condition of if statement can
be any valid logical expression
which can be either evaluated to
true or false

• 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

• NOTE: Here, the statements can


be a single statement or the group
of statements. The expression
should be any valid C expression
resulting into true or false. The
true is any non-zero value.
• Example
• Write a program print 1 to 5 using while loop.
• Write a C program that calculates the sum of n-natural nu
mbers.
For Loops in C
• The for loop in C is used to iterate the statements or a
part of the program several times. It is frequently used to
traverse the data structures like list, tuple, or dictionary.

• With the for loop we can execute a set of statements, once


for each item in a list, tuple, set etc.
• The syntax of for loop in C is
given below.
• for(initialize;
check_condition; update)
• { //do this }

• 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.

for ( initialization; condition; increment )


{
for ( initialization; condition; increment )
{ // statement of inside loop
}
// statement of outer loop
}
Example
• #include<stdio.h>
• for(int i=1;i<=3;i++)
• {
• for(int j=0;j<=4;j++)
• {
• if(j==3)
• {
• continue;
• }
• printf(“%d”, j );
• }
• printf(“\n”);
• }
• return 0;
• Output:-
• 0124
• 0124
• 0124
Program on Nested for loop
• Write a C program to display the following pattern
• 1
• 12
• 1234
• 12345

• Write a C program to display the following pattern


• 1
• 22
• 333
• 4444

• Write a C program to display the following pattern


• ******
• ******
• ******
• ******
• ******
• Write a C program to display the following pattern
•*
• **
• ***
• ****
• *****

• Write a C program to display following pattern


• *
• * *
• * * *
• * * * *
• * * * *
Break statement in C
• The break is a keyword in C which is used to bring the
program control out of the loop.
• The break statement breaks the loops one by one, i.e., in the
case of nested loops, it breaks the inner loop first and then
proceeds to outer loops. In other words, we can say that break
is used to abort the current execution of the program and the
control goes to the next line after the loop.
• The break is commonly used in the cases where we need to
break the loop for a given condition.
• The syntax of the break is given below.
▫ #loop statements
●break;
Continue statement in C

• The C continue statement resets program control to


the beginning of the loop when encountered.
• As a result, the current iteration of the loop gets
skipped and the control moves on to the next
iteration. Statements after the continue statement in
the loop are not executed.
• The syntax of the break is given below.
• #loop statement
continue
Example
Flowchart
• int main()
• {
• int i = 0;
• while (i < 4)
• {
• if (i == 2)
• {
• i++;
• continue;
• }
• printf("%d\n", i);
• i++;
• }
• return 0;
• }
• OUTPUT:-
• 0
• 1
Example
Continue
Break
• #include<stdio.h> • #include<stdio.h>
• int main(){ • int main(){
• int i=1; • int i=1;
• while(i<5){ • for(i=1;i<5;i++)
• if(i==2){ • {
• break; • if(i==2){
• } • continue;
• printf(“%d\n”,i); • }
• i++; • printf(“%d\n”,i)
• } • }
• return 0; • }
} • return 0;
• Output: • Output:
• 0 • 1
• 1 • 3
• 4
Exemplar/Case Studies
Design simple calculator and
Generating a Calendar

Write a Program to implement simple


calculator.

Write a Program to generate a Calen


dar
Book to refer

Let Us C - Yashwant Kanetkar

C by E Balagurusamy

Programming in ANSI C by Balagurus

wamy
Thank You

You might also like