Professional Documents
Culture Documents
Military Institute of Science and Technology
Military Institute of Science and Technology
Technology
Department of Naval Architecture and Marine Engineering
Lecture – 04
Topics- Arithmetic Operators and Expressions,
Decisions & For Loop
➢ Using #define
Example:
# include <iostream>
#define PI 3.14159
int main(){
float base, x, angle, el, height;
Solve >> cout <<"Enter the eye level from ground: ";
cin >> el;
Operator Description
== Equal to
!= Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
Unary Arithmetic Operator
• Increment: The ‘++’ operator is used to increment the value of an
integer. When placed before the variable name (also called pre-
increment operator), its value is incremented instantly. For example,
++x.
And when it is placed after the variable name (also called post-
increment operator), its value is preserved temporarily until the
execution of this statement and it gets updated before the execution
of the next statement. For example, x++.
• Decrement: The ‘– –‘ operator is used to decrement the value of an
integer. When placed before the variable name (also called pre-
decrement operator), its value is decremented instantly. For example,
– –x.
And when it is placed after the variable name (also called post-
decrement operator), its value is preserved temporarily until the
execution of this statement and it gets updated before the execution
of the next statement. For example, x– –.
Increment Operator
count = count +1
• count += 1
++count
Prefix and Postfix
Increment Prefix ++a Adds 1 to x =10, y=10
the y=++x
y=11, x=11
existing
Postfix a++ value of its x =10, y=10
operand y=x++
y=10, x=11
int main()
{
int n;
return 0;
}
Class Task 5
Checking a number prime or not
Solve >>
Class Task 6
Display factors of a number
Solve >>
Class Task 7
Display Fibonacci Series
Solve >>
Class Task 8
Check a number Palindrome or not
Solve >>
Assignment
1. Display prime numbers between two intervals
2. Display first 10 odd/even natural numbers and their sum
3. Write a program in C++ to find the complex roots of the quadratic equation
4x2 - 2x + 3 = 0
4. Write a program in C++ to find all the numbers between 200 to 300 that are
divisible by 8 and find their sum.
5.