Wednesday, November 21, 2012

Operator Aritmatika, Bitwise dan Logika


Listing program Operator Aritmatika : 

/*Nama: Izmatul Farihah
NIM: 49012057*/

/* Operator Aritmatika
+,-,*,/,% */

#include <iostream>

using namespace std;

int main (void){

cout<<"3+4="<<3+4<<endl;

cout<<"5-9="<<5-9<<endl;

cout<<"9*8="<<9*8<<endl;

cout<<"8/4="<<8/4<<endl;

cout<<"9%8="<<9%8<<endl;

system("pause");
return 0;
}

Listing Program Operator Bitwise : 

/*Nama: Izmatul Farihah
NIM: 49012057*/

/* Operator Bitwise
<<, >>, &, |, ~, ^ */

#include <iostream>

using namespace std;

int main (void){

int a=3, b; //0011
b=a<<1; //0110 = 6
cout<<"Nilai dari 3<<1= "<<b<<endl;

int x=4, y; //0100
y=x>>1; //0010
cout<<"Nilai dari 4>>1= "<<y<<endl;

int z=3, i=2, j, k, l; //0011 & 0010 = 0010
j=3&2;
cout<<"Nilai dari 3&2 = "<<j<<endl;
k=3|2; //0011 | 0010 = 0011;
cout<<"Nilai dari 3 | 2 = "<<k<<endl;
cout<<"Nilai dari ~3 = "<<~z<<endl; //1100 = -4

l=z^i; //0011 ^ 0010= 0001=1
cout<<"Nilai dari 3 ^2 = "<<l<<endl;

system("pause");
return 0;
}

Listing Program Operator Logika : 

/*Nama: Izmatul Farihah
NIM: 49012057*/

/* Operator Logika
&&, ||, ! */

#include <iostream>

using namespace std;

int main (void){

int a, b, c;
a=(3<4) && (6>8); // 1 && 0= 0
b=(3<4) || (6>8); // 1 || 0= 1
c=!(3<4); //1, !=0
cout<<"Hasil perbandingannya adalah : "<<a<<endl;
cout<<"Hasil Perbandingan or adalah : "<<b<<endl;
cout<<"Kebalikannya adalah : "<<c<<endl;


system("pause");
return 0;
}


No comments:

Post a Comment