Tuesday, November 20, 2012

Operator pada c++: Logika, Bitwise, Aritmatik, Ternary, Unary, dll.


/*Nama: Izmatul Farihah
NIM: 49012057*/

#include <iostream>

using namespace std;

int main (void){

cout<<"Operator Assignment"<<endl;
int a, b;
a=b=7;
cout<<"Nilai a : "<<a<<endl;
cout<<"Nilai b : "<<b<<endl<<endl;

cout<<"Operator Aritmatika"<<endl;
int c=10, d=2, e;
e=c+d/2;
cout<<"Nilai e : "<<e<<endl<<endl;

cout<<"Operator Unary"<<endl;
e=-d;
cout<<"Nilai e : "<<e<<endl<<endl;

cout<<"Operator Increment"<<endl;
cout<<"Nilai d++ : "<<d++<<endl;
cout<<"Nilai ++c : "<<++c<<endl<<endl;

cout<<"Operator Decrement"<<endl;
int f=10, g=9;
cout<<"Nilai f-- : "<<f--<<endl;
cout<<"Nilai --g : "<<--g<<endl<<endl;

cout<<"Operator Logika"<<endl;
int h;
h=(4>2) || (9>10);
cout<<"Nilai h : "<<h<<endl<<endl;

cout<<"Operator Bitwise"<<endl; //<< >> & |
int i=3, j; //0011
j=i>>1; //0110
cout<<"Nilai j : "<<j<<endl<<endl;

cout<<"Operator Ternary"<<endl; //? :
int k=8, l;
l=(k>10)?1:0;
cout<<"Nilai l : "<<l<<endl<<endl;

system("pause");
return 0;
}

No comments:

Post a Comment