pre{ background:#f8f9fa; border:1px solid #ddd; border-left:4px solid #1565C0; padding:15px; margin:15px 0; overflow-x:auto; white-space:pre; font-family:Consolas, Monaco, monospace; font-size:15px; line-height:1.6; height:auto; min-height:0; }
FREE E LEARNING PLATFORM
HOMEEXCEPTIONSOOPSJVMINTRO
 

DSTL Lab Programs (Discrete Structures and Theory of Logic)

Important Laboratory Programs in C



DSTL Lab Programs in C

Introduction

The Discrete Structures and Theory of Logic (DSTL) laboratory is an important part of the B.Tech Computer Science and Engineering curriculum. The objective of this laboratory is to provide practical knowledge of Set Theory, Boolean Algebra and Graph Theory using the C programming language.

This tutorial covers the most important laboratory experiments prescribed in the AKTU syllabus. Each experiment includes the aim, theory, algorithm, C program, sample output and explanation to help students perform practicals confidently and prepare for viva examinations.


List of Laboratory Experiments

Experiment Program
Experiment 1 Write a program in C to create two sets and perform the Union operation.
Experiment 2 Write a program in C to create two sets and perform the Intersection operation.
Experiment 3 Write a program in C to create two sets and perform the Difference operation.
Experiment 4 Write a program in C to create two sets and perform the Symmetric Difference operation.
Experiment 5 Write a program in C to generate the Power Set of a given set.
Experiment 6 Write a program in C to display the Boolean Truth Table for AND, OR and NOT.
Experiment 7 Write a program in C to find the Cartesian Product of two sets.
Experiment 8 Write a program in C to find the Minimum Cost Spanning Tree using Prim's Algorithm.
Experiment 9 Write a program in C to find the Shortest Path in a graph using Dijkstra's Algorithm.

Prerequisites

  • Basic knowledge of the C programming language.
  • Understanding of arrays, loops and conditional statements.
  • Knowledge of Set Theory.
  • Basic understanding of Boolean Algebra.
  • Introduction to Graph Theory.

Software Requirements

Software Purpose
Turbo C++ / Dev C++ Writing and executing C programs.
Code::Blocks C Programming IDE.
Visual Studio Code Writing and compiling C programs.
GCC Compiler Compilation of C source code.

Learning Outcomes

After completing these laboratory experiments, students will be able to:

  • Perform different Set operations using C.
  • Generate the Power Set of a given set.
  • Construct Boolean Truth Tables.
  • Implement Cartesian Product of sets.
  • Develop Minimum Cost Spanning Tree using Prim's Algorithm.
  • Find the Shortest Path using Dijkstra's Algorithm.
  • Strengthen logical and analytical programming skills.

Union of Two Sets

Experiment 1 : Union of Two Sets

Aim

Write a program in C to create two sets and perform the Union operation.

Theory

The Union of two sets is the collection of all distinct elements that are present in either Set A, Set B or both sets. The Union of two sets is represented by the symbol A ∪ B.

A ∪ B = { x | x ∈ A or x ∈ B }

For example,

A = {1,2,3,4}
B = {3,4,5,6}

A ∪ B = {1,2,3,4,5,6}


Algorithm

  1. Read the number of elements in Set A.
  2. Read all elements of Set A.
  3. Read the number of elements in Set B.
  4. Read all elements of Set B.
  5. Copy all elements of Set A into the Union Set.
  6. Compare every element of Set B with the Union Set.
  7. If an element is not already present, insert it into the Union Set.
  8. Display the Union Set.

C Program

#include

int main()
{
    int A[20],B[20],U[40];
    int m,n,i,j,k=0,found;

    printf("Enter number of elements in Set A : ");
    scanf("%d",&m);

    printf("Enter elements of Set A :\n");

    for(i=0;i


Sample Output

Enter number of elements in Set A : 4

Enter elements of Set A :
1 2 3 4

Enter number of elements in Set B : 4

Enter elements of Set B :
3 4 5 6

Union of Sets = { 1 2 3 4 5 6 }

Explanation

Initially, all elements of Set A are copied into the Union Set. The elements of Set B are then compared with the existing elements. If an element is not already present, it is inserted into the Union Set. Thus, duplicate elements are eliminated and the final result contains every distinct element from both sets.


Result

The program successfully performs the Union operation on two sets and displays the resulting Union Set.