Print a truth table for the logical operators

image_pdfimage_print

   
 
/*
C# A Beginner's Guide
By Schildt

Publisher: Osborne McGraw-Hill
ISBN: 0072133295
*/
/* 
   Project 2-2 
 
   Print a truth table for the logical operators. 
*/ 
 
using System; 
 
public class LogicalOpTable {    
  public static void Main() {    
 
    bool p, q; 
 
    Console.WriteLine("P	Q	AND	OR	XOR	NOT"); 
 
    p = true; q = true; 
    Console.Write(p + "	" + q +"	"); 
    Console.Write((p&q) + "	" + (p|q) + "	"); 
    Console.WriteLine((p^q) + "	" + (!p)); 
 
    p = true; q = false; 
    Console.Write(p + "	" + q +"	"); 
    Console.Write((p&q) + "	" + (p|q) + "	"); 
    Console.WriteLine((p^q) + "	" + (!p)); 
 
    p = false; q = true; 
    Console.Write(p + "	" + q +"	"); 
    Console.Write((p&q) + "	" + (p|q) + "	"); 
    Console.WriteLine((p^q) + "	" + (!p)); 
 
    p = false; q = false; 
    Console.Write(p + "	" + q +"	"); 
    Console.Write((p&q) + "	" + (p|q) + "	"); 
    Console.WriteLine((p^q) + "	" + (!p)); 
  }    
}



           
         
     


This entry was posted in Data Types. Bookmark the permalink.