Professional Documents
Culture Documents
#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
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 ;
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>
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