You are on page 1of 6

Arithmatic Operator

#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int a = 21;
int b = 10;
int c;
c = a + b;
cout << "Apabila
c = a - b;
cout << "Apabila
c = a * b;
cout << "Apabila
c = a / b;
cout << "Apabila
c = a % b;
cout << "Apabila
c = a++;
cout << "Apabila
c = a--;
cout << "Apabila

a + b nilai c adalah :" << c << endl ;


a - b nilai c adalah :" << c << endl ;
a * b nilai c adalah :" << c << endl ;
a / b nilai c adalah :" << c << endl ;
a % b nilai c adalah :" << c << endl ;
a ++ nilai c adalah :" << c << endl ;
a -- nilai c adalah :" << c << endl ;

cout << "Please press any key to exit... " << endl;
getch();
}

Rational Operator
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int a = 21;
int b = 10;
int c ;
if( a == b )
{
cout << "Example 1 - a is equal to b" << endl ;
}
else
{
cout << "Example 1 - a is not equal to b" << endl ;
}
if ( a < b )
{
cout << "Example 2 - a is less than b" << endl ;
}
else
{
cout << "Example 2 - a is not less than b" << endl ;
}
if ( a > b )
{
cout << "Example 3 - a is greater than b" << endl ;
}
else
{
cout << "Example 3 - a is not greater than b" << endl ;
}
/* Let's change the values of a and b */
a = 5;
b = 20;
if ( a <= b )
{
cout << "Example 4 - a is either less than \ or euqal to b" << endl ;
}
if ( b >= a )
{
cout << "Example 5 - b is either greater than \ or equal to b" << endl ;
}

cout << "Please press any key to exit... " << endl;
getch();

Logical Operator

#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
cout << "Enter a number: ";
int value;
cin >> value ;

if (value > 10 && value < 20)


cout << "Your value is between 10 and 20.. The answer is true.." << endl;
else
cout << "You value is not between 10 and 20.. The answer is false.." << endl;
cout << "Please press any key to exit... " << endl;
getch();

Another sample for Logical


#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
double mark;
cout << "Enter your Test 1 mark >>";
cin >> mark;
if (mark >= 30)
cout << "Test 1 -> Pass..! Good job Buddy.. Congratulation :) :) " << endl;
if (mark < 30)
cout << "Test 1 -> Fail...:( Go back and practise.. " << endl;

cout << "Please press any key to exit... " << endl;
getch();
}

Assignment Operator

#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int a = 21;
int c ;
c = a;
cout << "Line 1 - = Operator, Value of c = : " <<c<< endl ;
c += a;
cout << "Line 2 - += Operator, Value of c = : " <<c<< endl ;
c -= a;
cout << "Line 3 - -= Operator, Value of c = : " <<c<< endl ;
c *= a;
cout << "Line 4 - *= Operator, Value of c = : " <<c<< endl ;
c /= a;
cout << "Line 5 - /= Operator, Value of c = : " <<c<< endl ;

cout << "Please press any key to exit... " << endl;
getch();

Contoh m/s 23
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int year, age;
cout << "Please enter year: ";
cin >> year;
age = year - 1992;
cout << "In year " << year << ", " << endl;
cout << "I am " << age << " years old." << endl;
cout << "Please press any key to exit... " << endl;
getch();
}

Contoh m/s 27
#include <iostream>
#include <conio.h>

using namespace std;


void main()
{
float radius, volume, area;

cout << "Enter the radius: ";


cin >> radius;
volume = (4.0/3) *3.14*radius*radius*radius;
cout << "\nThe volume of a spehere with radius "
<< radius << " is " << volume;
area = 3.14*radius*radius;
cout << "\nThe area of a circle with radius "
<< radius << " is " << area << endl;
cout << "Please press any key to exit... " << endl;
getch();

Contoh M/s 16
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int x, y;
x = 2;
y = 4;
cout << x << " " << y << endl;
cout << "Please press any key to exit" << endl;
getch();
}

Contoh m/s 78
#include <iostream>
#include <conio.h>
using namespace std;

void main()
{
int jumlah_ringgit, baki;
int bil_limapuluh, bil_duapuluh, bil_sepuluh, bil_lima, bil_satu;
cout << "\n\nMasukkan jumlah ringgit: ";
cin >> jumlah_ringgit;
bil_limapuluh = jumlah_ringgit / 50;
baki = jumlah_ringgit % 50;
bil_duapuluh = baki / 20;
baki = baki % 20;
bil_sepuluh = baki / 10;
baki = baki % 10;
bil_lima = baki / 5;
bil_satu = baki % 5;
cout
cout
cout
cout
cout

<<
<<
<<
<<
<<

"\nBilangan
"\nBilangan
"\nBilangan
"\nBilangan
"\nBilangan

RM50 : " << bil_limapuluh;


RM20 : " << bil_duapuluh;
RM10 : " << bil_sepuluh;
RM5 : " << bil_lima;
RM1 : " << bil_satu << endl;

cout << "Please press any key to exit" << endl;


getch();

You might also like