0% found this document useful (0 votes)
9 views39 pages

Mathematical Functions & Conditions in C++: Dr. Haiam Adel

Uploaded by

j8j98mj2jw
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)
9 views39 pages

Mathematical Functions & Conditions in C++: Dr. Haiam Adel

Uploaded by

j8j98mj2jw
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/ 39

Mathematical Functions

& Conditions in C++

Dr. Haiam Adel


Lecture Outlines

• Mathematical Functions
• Compound operators
• Conditional operator
• Logical operators
• IF statement
• switch statement
Mathematical Functions

• Math library functions #include


<math.h> allow the programmer to
perform a number of common
mathematical calculations:
Examples:-

• Write a C++ program that ask


the user to enter an angle
value and calculate the Value
of sin(x).
Examples:

• Write a C++ program to


computes the Value of X n.
Examples:

• Write a C++ program to


computes the Value of √𝑥.
Examples:-

• Write a C++ program that assign the


value of variable b to the variable a
and then add 2 to the value of a.
Examples:

• Write a C++ program that


returns the greatest number
among two integer variable's
value using the conditional
operator.
Examples:

• Write a C++ program that asks


the user to enter his marks and
returns “passed“ if the marks is
greater than or equal 40 and
returns “failed” if the marks is
less than 40 using the
conditional operator.
Examples:

• Write a C++ program that asks


the user to enter a number and
returns a message if it is a
positive or negative number
using the conditional operator.
If Statement in C++
• In computer programming, we use the if-statement to run one block of code
under certain conditions and another block of code under different conditions.
Examples:

• Write a C++ program that asks


the user to enter a number and
returns a message if it is a
positive or negative number.
Examples:

• Write a C++ program that asks


the user to enter a number and
returns a message if it is a
positive or negative number.
Examples:

• Write a C++ program that asks


the user to enter an integer
and checks whether this
number is positive, negative or
zero.
Examples:

• Write a C++ program that asks


the user to enter an integer
and checks whether this
number is positive, negative or
zero using nested if
statments.
Logical Operators
• logical operators are expressions that combine two or more conditions to obtain a
single relational result.
Examples:

• Write a C++ program that


prompts the user for three
numbers and prints the greatest
of them.
Examples:

• Write a C++ program that


prompts the user for three
numbers and prints the greatest
of them.

• Other solutions:
Examples:

• Write a C++ program that


returns the discount percentage
for supermarket customers that
buy 100 pieces or their total
payment is greater than 1000 L.E.
switch statement

• The switch-statement allows us to


execute a block of code among many
alternatives. It can do the same things as
nested if-statement. However, the syntax
of the switch-statement is cleaner and
much easier to read and write.

• The syntax of the switch-statement in


C++ is:
Examples:

• Write a C++ program that returns


the day of the week depending
on the entered value of the
variable day. It assumes that day
1 is Sunday.
Examples:

• Write a C++ program that returns


a message represents whether
the entered day number is a
weekday or is part of week end.
Examples:

• Write a C++ program that returns


a message represents whether
the entered day number is a
weekday or is part of week end.

• This program can also written


with If-statement as:
Examples:

• Write a C++ program that creates


a simple calculator using switch-
statement.
Thank you ☺

You might also like