






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































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)
“Write a program in C to create two sets and perform the Intersection operation of these two sets.” Software used :
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
“C program to find Complement of a set.” Software used :
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
“Write a program in C to create two sets and perform symmetric difference operation on these two sets.” Software used :
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
“Write a C program to find Cartesian product of two sets.” Software used :
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
“Write a C program to find power set of a given set.” Software used :
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.