Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

COMPUTER

PROGRAMMING
LECTURE #04

ARITHEMETIC OPERATORS
C++ COMMENTS

• Comments can be used to explain C++ code, and to make it more readable. It can also be
used to prevent execution when testing alternative code. Comments can be singled-lined
or multi-lined.
SINGLE-LINE COMMENTS

• Single-line comments start with two forward slashes (//).

• Any text between // and the end of the line is ignored by the compiler (will not be
executed).

• This example uses a single-line comment before a line of code:


• // This is a comment
C++ MULTI-LINE COMMENTS

• Multi-line comments start with /* and ends with */.

• Any text between /* and */ will be ignored by the compiler:


/* The code below will print the words Hello World!
to the screen, and it is amazing */
cout << "Hello World!";
C++ OPERATORS

• Operators are used to perform operations on variables and values.

• In the example below, we use the + operator to add together two values:

• int x = 100 + 50;


ARITHMETIC OPERATORS

• Arithmetic operators are used to perform common mathematical operations.


PLUS + OPERATOR

#include <iostream>

using namespace std;

int main() {

int x = 5;

int y = 3;

cout << x + y;

return 0;

Output:

8
MINUS – OPERATOR

#include <iostream>

using namespace std;

int main() {

int x = 5;

int y = 3;

cout << x - y;

return 0;

Output:

2
MULTIPLY * OPERATOR

#include <iostream>

using namespace std;

int main() {

int x = 5;

int y = 3;

cout << x * y;

return 0;

Output:

15
DIVIDE / OPERATOR

#include <iostream>
using namespace std;

int main() {
int x = 12;
int y = 3;
cout << x / y;
return 0;
}
Output:
4
MODULUS % OPERATOR

#include <iostream>
using namespace std;

int main() {
int x = 5;
int y = 2;
cout << x % y;
return 0;
}

Output:
1

You might also like