The operands of a logical operation must be of type bool and the result is, as well, of type bool. The bool type represents true/false values.
using System;
class TruthTable
{
static void Main()
{
bool p, q;
Console.WriteLine("_____________________________________________");
Console.WriteLine("\n P \tQ\tAND\tOR\tXOR\tNOT");
Console.WriteLine("_____________________________________________");
p = true; q = true;
Console.WriteLine(" "+p+"\t"+q+"\t"+(p&q)+"\t"+(p|q)+"\t"+(p^q)+"\t"+(!p));
Console.WriteLine("_____________________________________________");
p = true; q = false;
Console.WriteLine(" "+p+"\t"+q+"\t"+(p&q)+"\t"+(p|q)+"\t"+(p^q)+"\t"+(!p));
Console.WriteLine("_____________________________________________");
p = false; q = true;
Console.WriteLine(" "+p+"\t"+q+"\t"+(p&q)+"\t"+(p|q)+"\t"+(p^q)+"\t"+(!p));
Console.WriteLine("_____________________________________________");
p = false; q = false;
Console.WriteLine(" "+p+"\t"+q+"\t"+(p&q)+"\t"+(p|q)+"\t"+(p^q)+"\t"+(!p));
Console.WriteLine("_____________________________________________");
Console.Read();
}
}

No comments:
Post a Comment