#include
void main()
{
int w1,w2,x1,x2,out;
w1=1;w2=1;
cout<<" Input x1= "; cin>> x1;
cout<<" Input x2= "; cin>> x2;
out=x1*w1+x2*w2;
if(out>=2)
cout<<" output AND = 1 "; else cout<<" output AND = 0 ";}
2.Gerbang Logika OR
#include
void main()
{
int w1,w2,x1,x2,out;
w1=2;w2=2;
cout<<" Input x1= "; cin>> x1;
cout<<" Input x2= "; cin>> x2;
out=x1*w1+x2*w2;
if(out>=2)
cout<<" output OR = 1 "; else cout<<" output OR = 0 ";}
3.Gerbang Logika NOT
#include
void main()
{
double w1,w2,x1,x2,out;
w1=-1;
cout<<" Input x1= "; cin>> x1;
out=x1*w1;
if(out>=-0.5)
cout<<" output NOT = 1 "; else cout<<" output NOT = 0 ";}
4. Gerbang Logika XOR
#include
void main()
{float x1,x2,f1,f2,z1,z2,B,bin;
cout<<"masukkan nilai X1= "; cin>>x1;
cout<<"masukkan nilai X2= "; cin>>x2;
f1=(x1*2)+(x2*(-1));
f2=(x1*(-1))+(x2*2);
{if (f1<2)
z1=0;
else
z1=1;}
{if (f2<2)
z2=0;
else
z2=1;}
B=z1*1+z2*1;
{if (B<1)
bin=0;
else
bin=1;}
cout<<"out= "<<bin;}
Artikel Terkait
1 komentar :
Udh nyoba tp eror
Posting Komentar