Skip to main content

Print the Truth Table

#include<stdio.h>

int OR(int,int);
int AND(int,int);
int XOR(int,int);
int NOT(int);

void main()
{
int a,b,ch,o;

printf("\n-:MENU:-\n1.AND\n2.OR\n3.NOT\n4.XOR\n0.Exit\n");
do{
printf("\nEnter Choice:");
scanf("%d",&ch);

switch(ch)
{
case 1:
printf ("\nTruth Table for AND\nA B \tO");
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
o=AND(a,b);
printf("\n%d %d \t%d",a,b,o);
}
}
break;
case 2:
printf ("\nTruth Table for OR\nA B \tO");
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
o=OR(a,b);
printf("\n%d %d \t%d",a,b,o);
}
}
break;
case 3:
printf ("\nTruth Table for NOT\nA \tO");
for(a=0;a<=1;a++)
{
o=NOT(a);
printf("\n%d \t%d",a,o);
}
break;
case 4:
printf ("\nTruth Table for XOR\nA B \tO");
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
o=XOR(a,b);
printf("\n%d %d \t%d",a,b,o);
}
}
break;

case 0: exit();
break;
default: printf("\nError");
}
}while(ch!=0);

}


int OR(int a, int b)
{
if(a==0&&b==0)
return 0;
else
return 1;
}

int AND(int a, int b)
{
if (a==1&&b==1)
return 1;
else
return 0;
}

int NOT(int a)
{
if (a==0)
return 1;
else
return 0;
}

int XOR(int a,int b)
{
if (a==0&&b==1||a==1&&b==0)
return 1;
else
return 0;
}

  

Comments

Popular posts from this blog

Addition of two numbers on Server sent from Client [TCP] using C

/* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <strings.h> #define MAX_MSG 100 #define SERVER_ADDR "127.0.0.1" #define CLIENT_ADDR "127.0.0.1" #define SERVER_PORT 3786 #define CLIENT_PORT 8229  main () {   int sd, rc, i,n;   struct sockaddr_in clientAddr, servAddr;   char line[MAX_MSG];   /**********************************/   /* build server address structure */   /**********************************/   bzero((char *)&servAddr, sizeof(servAddr));   servAddr.sin_family = AF_INET;   servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);   servAddr.sin_port = htons(SERVER_PORT); /*   bzero((char *)&servAddr, sizeof(servAddr));   servAddr.sin_family = AF_INET;   inet_aton(SERVER_ADDR, &servAddr.sin_addr);   servAddr.sin_port = htons(SERVER_PORT); */   /*****

Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle

/* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Rectangle { protected: float length, breadth; public: Rectangle(): length(0.0), breadth(0.0) { cout<<"Enter length: "; cin>>length; cout<<"Enter breadth: "; cin>>breadth; } }; /* Area class is derived from base class Rectangle. */ class Area : public Rectangle { public: float calc() { return length*breadth; } }; /* Perimeter class is derived from base class Rectangle. */ class Perimeter : public Rectangle { public: float calc() { return 2*(length+breadth); } }; int main() { cout<<"Enter data for first rectangle to find area.\n"; Area a; cout<<"Area = "<

C program for Unit Conversion

/* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ");     scanf("%f",&c);     f = c * 9/5 + 32;     printf("Temperature in Farenheit: %f",f); } /* Convert Farenheit to Celcius */ #include<stdio.h> void main() {     float c,f;     printf("Farenheit : ");     scanf("%f",&f);     c = (f - 32) * 5/9;     printf("Celcius: %f",c);  } /*Convert Meter to Feet*/ #include<stdio.h> void main() {     float m,f;     printf("Meter : ");     scanf("%f",&m);     f = 3.2808399 * m;     printf("Feet: %f",f); } /* Convert Feet to Meter */ #include<stdio.h> void main() {     float m,f;     printf("Feet : ");     scanf("%f",&f);     m = f / 3.2808399;     printf("Meter: %f",m); } /*Convert Km to M/cm/mm*/ #include<stdio.h> void main() {   float km;   char v;   float