Docsity

Discrete mathematics lab manual, Lab Reports of Discrete Mathematics

Partial preview of the text

Download Discrete mathematics lab manual and more Lab Reports Discrete Mathematics in PDF only on Docsity!

Department Of Computer Science And Engineering

Affiliated to Dr. A.P.J. AKTU, Lucknow

LAB FILE

Subject Name: Discrete Structure & Logic Lab

Subject Code: KCS-

Session : 2020-21 (ODD SEMESTER)

Semester : III

Submitted By:

Name : Harshit Mishra

Roll No. : 1902900100067

Section : 2CSA

INDEX

S.No

Experiment Name Page No. Experiment Date Submission Date Remarks

  1. (1a.) Write a program in C to create two sets and perform the union operation on sets. (1b.) Write a program in C to create two sets and perform the Intersection operation of these two sets.
  1. C program to find Complement of a set 7-9 28/09/2020^ 05/10/
  2. Write a program in C to create two sets and perform symmetric difference operation on these two sets.

10-12 05/10/2020^ 12/10/

  1. Write a C program to find Cartesian product of two sets. 13-14 12/10/2020^ 19/10/
  2. Write a C program to verify Truth Table of AND, OR & NOT Gate. 15-16 19/10/2020^ 26/10/
  3. (^) Write a C program to find power set of a given set. 17-19 26/10/2020^ 02/11/
  4. (^) BASICS OF PROLOG (PROGRAMMING IN LOGIC)” 20-26 02/11/2020^ 20/11/ (^8) Prolog program for queries related to a given knowledge base. 27-28 02/11/2020^ 20/11/
  5. Prolog program for generating family tree. 29-31 20/11/2020^ 27/11/
  6. Prolog program for graph coloring. (^) 32-34 27/11/2020 04/12/
  7. Prolog program for generating birthday problem. 35-36 04/12/2020^ 11/12/

printf(" }"); printf("\n\n Union is : \n {"); for(i=0;i<p;i++) { printf("%d,\t",a[i]); } for(i=0;i<q;i++) { for(j=0;j<p;j++) { if(b[i]==a[j]) { flag=1; } } if(flag==0) { printf("%d,\t",b[i]); } flag=0; } printf(" }"); getch(); } Observations : OUTPUT :

Experiment No. – 1(b)

Objective :

“Write a program in C to create two sets and perform the Intersection operation of these two sets.” Software used :

Turbo C++

CODE : #include<stdio.h> #include<conio.h> void main() { int a[20],b[20],flag=0,p,q,i,j; clrscr(); printf("Enter set 1 size : "); scanf("%d",&p); printf("\n Enter set 1 elements : "); for(i=0;i<p;i++) { scanf("%d",&a[i]); } printf("\n Set 1 elements are :\n {"); for(i=0;i<p;i++) { printf("\t %d, ",a[i]); } printf(" }"); printf("\n\n Enter set 2 size : "); scanf("%d",&q); printf("\n Enter set 2 elements : "); for(j=0;j<q;j++) { scanf("%d",&b[j]); } printf("\n Set 2 elements are :\n {"); for(j=0;j<q;j++) {

Experiment No. – 2

Objective :

“C program to find Complement of a set.” Software used :

Turbo C++

CODE : #include<stdio.h> #include<conio.h> void main() { int a[20],b[20],c[20],p,q,i,j,ch,k,fl=0; clrscr(); printf("Enter set 1 size : "); scanf("%d",&p); printf("\n Enter set 1 elements : "); for(i=0;i<p;i++) { scanf("%d",&a[i]); } printf("\n Set 1 elements are :\n{ "); for(i=0;i<p;i++) { printf("\t %d, ",a[i]); } printf(" }"); printf("\n\n Enter set 2 size : "); scanf("%d",&q); printf("\n Enter set 2 elements : "); for(j=0;j<q;j++) { scanf("%d",&b[j]); } printf("\n Set 2 elements are :\n {"); for(j=0;j<q;j++) { printf("\t %d, ",b[j]);

printf(" }"); printf("\n Which operation would you like to perform?\n 1. A-B \n 2.B-A \n Enter your choice (1/2) "); scanf("%d",&ch); if(ch==1||ch==2) { switch(ch) { case 1: k=0; for(i=0;i<p;i++) { fl=0; for(j=0;j<q;j++) { if(a[i]==b[j]) { fl=0; break; } else { fl=1; } } if(fl==1) { c[k]=a[i]; k++; } } printf("\n Difference is A-B : { "); break; case 2: k=0; for(i=0;i<p;i++) { fl=0; for(j=0;j<q;j++) { if(b[i]==a[j]) { fl=0; break; } else { fl=1; }

Experiment No. – 3

Objective :

“Write a program in C to create two sets and perform symmetric difference operation on these two sets.” Software used :

Turbo C++

CODE : #include<stdio.h> #include<conio.h> void main() { int a[20],b[20],c[20],p,q,i,j,k,fl=0; clrscr(); printf("Enter set 1 size : "); scanf("%d",&p); printf("\n Enter set 1 elements : "); for(i=0;i<p;i++) { scanf("%d",&a[i]); } printf("\n Set 1 elements are :\n{ "); for(i=0;i<p;i++) { printf("\t %d, ",a[i]); } printf(" }"); printf("\n\n Enter set 2 size : "); scanf("%d",&q); printf("\n Enter set 2 elements : "); for(j=0;j<q;j++) {

scanf("%d",&b[j]); } printf("\n Set 2 elements are :\n {"); for(j=0;j<q;j++) { printf("\t %d, ",b[j]); } printf(" }"); k=0; for(i=0;i<p;i++) { fl=0; for(j=0;j<q;j++) { if(a[i]==b[j]) { fl=0; break; } else { fl=1; } } if(fl==1) { c[k]=a[i]; k++; } } for(i=0;i<p;i++) { fl=0; for(j=0;j<q;j++) { if(b[i]==a[j]) { fl=0; break; } else { fl=1; } } if(fl==1) { c[k]=b[i]; k++; }

Experiment No. – 4

Objective :

“Write a C program to find Cartesian product of two sets.” Software used :

Turbo C++

CODE : #include<stdio.h> #include<conio.h> void main() { int a[20],b[20],p,q,i,j; clrscr(); printf("Enter set 1 size : "); scanf("%d",&p); printf("\n Enter set 1 elements : "); for(i=0;i<p;i++) { scanf("%d",&a[i]); } printf("\n Set 1 elements are :\n{ "); for(i=0;i<p;i++) { printf("\t %d, ",a[i]); } printf(" }"); printf("\n\n Enter set 2 size : ");

scanf("%d",&q); printf("\n Enter set 2 elements : "); for(j=0;j<q;j++) { scanf("%d",&b[j]); } printf("\n Set 2 elements are :\n {"); for(j=0;j<q;j++) { printf("\t %d, ",b[j]); } printf(" }"); printf("\n Cartesian product is : \n"); printf("{"); for(i=0;i<p;i++) { for(j=0;j<q;j++) { printf("(%d,%d)",a[i],b[j]); printf(","); } } printf("}"); getch(); } Observations : OUTPUT :

printf("\n Truth Table for AND(&&) is : \n"); printf(" A B : C=A&&B\n"); for(i=0;i<=1;i++) { for(j=0;j<=1;j++) { printf(" %d %d : %d\n",i,j,a[i][j]); } } printf("\n Truth Table for OR(||) is : \n"); printf(" A B : C=A||B\n"); for(i=0;i<=1;i++) { for(j=0;j<=1;j++) { printf(" %d %d : %d\n",i,j,b[i][j]); } } printf("\n Truth Table for NOT(!) is : \n"); printf(" A : !A\n"); for(i=0;i<=1;i++) { printf(" %d : %d\n",i,c[i]); } getch(); } Observations : OUTPUT :

Experiment No. – 6

Objective :

“Write a C program to find power set of a given set.” Software used :

Turbo C++

printf("\np(A)={ "); for(i=0;i<pi;i++) { printf(" { "); for(j=0;j<size;j++) { if(i&(1<<j)) { printf(" %d, ",a[j]); } } printf(" }, "); } } printf(" } "); getch(); } Observations : OUTPUT : ExperimentNo. – 7 Objective: “BASICS OF PROLOG (PROGRAMMING IN LOGIC)”

Introduction: Prolog is a general purpose programming language associated with artificial intelligence and computational linguistics. Prolog has its roots in first order logic and formal logic. Prolog is called declarative language or a rule-based language because its programs consist of a list of facts and rules. A computational is initiated by running a query over these relations. The general idea behind declarative language is that you describe a situation. Based on this code, the interpreter or compiler will tell you a solution. In the case of prolog, it will tell you whether a prolog sentence is true or not, and if it contains variables, what the values of the variables need to be. Prolog is a rich collection of data structures, human reasoning and a powerful notation for encoding end-user applications. It has its logical and declarative aspects, interpretive nature, compactness and inherent modularity. Features:  Based on logical programming with horn clauses.  Fully object oriented.  Object predicate values.