0% found this document useful (0 votes)
2 views32 pages

Operators in C++

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

Operators in C++

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

SIG

Day - 2
Data Types
Operators in C++
Arithmetic Operators
Assignment
Operators
These are used to
assign values to
variables.
Logical Operators
Relational
Operators
Relational operators
are used to compare
two values and
return a boolean
result (either true or
false).
Bitwise Operators
Other Operators
Operator Precedence

int a = 20; e = (a + b) * c / d;
int b = 10; e = ((a + b) * c) / d;
int c = 15; e = (a + b) * (c / d);
int d = 5;
e = a + (b * c) / d;
int e;
If Statement
If Else
Statement
An `if-else` statement is a conditional
structure that executes a block of code if
a specified condition is true, and another
block if the condition is false. It allows
decision-making based on logical
conditions.
If - else if - else
Statement
if : Evaluates the first condition; if true,
executes the corresponding code. If false,
checks the next condition.

else if : If the if condition is false, checks


each else if condition in order, executing
the first true one.

else : If none of the conditions are true,


the else block executes. (Optional)
Switch Statement
Syntax
It allows you to execute one
block of code out of many switch (expression) {
options based on the value of a case value_1:
variable or expression. // statements_1;
break;
case value_2:
The break statement is
// statements_2;
commonly used to exit from a break;
case once it has been executed. .....
.....
A default case can be used to default:
handle any value that doesn’t // default_statements;
break;
match the cases.
}
Calculator

Write a C++ program that implements a calculator


using switch statement, allowing the user to
choose addition, subtraction, multiplication,
division, or exit, and handle division by zero.
FE CARNIVAL
Loops
Loops are used when we need to repeatedly execute a
block of statements.

For Loop

While Loop

Do While Loop
For Loop
While Loop
Do While Loop
Break Statement
The break statement is used
to exit a loop or switch
statement immediately.

It terminates the current loop


and does not check the
remaining iterations.
Continue Statement
The continue statement skips
the remaining code inside the
loop for the current iteration
and jumps to the next
iteration.

When encountered, it does


not terminate the loop but
skips to the next iteration.
Patterns
**** * 1
**** ** 1 2
**** *** 1 2 3
**** **** 1 2 3 4
Maths Class

Need to include
<cmath>
cmath library provides a
variety of mathematical
functions

pow(base, exponent) - Raises the


base to the power of the exponent
floor(x)-Returns the largest integer
less than or equal to x (rounds down).
ceil(x) - Returns the smallest integer greater than or
equal to x (rounds up).
log(x) - Returns the natural logarithm value
sqrt(x) - Returns the
square root of x
sin(x), cos(x), tan(x)-These functions
return the sine, cosine, and tangent of an
angle x (in radians)
Swapping Two Numbers
Using a Temporary
Variable
Swapping Two Numbers
Today's Without using a
Temporary Variable
Task Hint - Using Arithmetic Operations
or
Using an In-Built function
Thank
You !

You might also like