DSTL Experiments
DSTL Experiments
DSTL Experiments
#include<stdio.h>
return 1;
return 1;
return 0;
return 1;
else
return 0;
int find_NOT(int x)
if(x==1)
return 0;
else
return 1;
}
// Driver function
int main()
int ch,a,b;
printf("1. OR\n");
printf("2. AND\n");
printf("3. NOT\n");
printf("4 .exit\n");
while(1)
scanf("%d",&ch);
switch(ch)
scanf("%d%d",&a,&b);
printf("%d",find_OR(a,b));
break;
scanf("%d%d",&a,&b);
printf("%d",find_AND(a,b));
break;
scanf("%d",&a);
printf("%d",find_NOT(a));
break;
case 4: exit(0);
}
}
Output:
Experiment -7
Write a program in c to find the cartesian product .
#include<stdio.h>
int main()
int a[10],b[10],n1,n2;
scanf("%d",&n1);
for(int i=0;i<n1;i++)
scanf("%d",&a[i]);
scanf("%d",&n2);
for(int i=0;i<n2;i++)
scanf("%d",&b[i]);
printf("{");
for(int i=0;i<n1;i++)
for(int j=0;j<n2;j++)
printf("}");
return 0;
}
Output:
Experiment-8
Write a program in c to implement relational and check
whether it is reflexive or not.
#include<stdio.h>
void main()
int a1[100],a2[100],i,j,n,n1,m[100][100],c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a1[i]);
scanf("%d",&n1);
for(j=0;j<n1;j++)
scanf("%d",&a2[j]);
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
if(a1[i]<a2[j]||a1[i]==a2[j])
{
m[i][j]=1;
else
m[i][j]=0;
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
printf("%d ",m[i][j]);
printf("\n");
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
c++;
if(c==n)
else
printf("relational matrix is not reflexive\n");
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
if(m[i][j]==1&&m[j][i]==1)
c++;
Output:
Experiment -9
Write a program to implement relational and check
whether it is symmetric or not.
#include<stdio.h>
void main()
int a1[100],a2[100],i,j,n,n1,m[100][100],c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a1[i]);
scanf("%d",&n1);
for(j=0;j<n1;j++)
scanf("%d",&a2[j]);
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
if(a1[i]<a2[j]||a1[i]==a2[j])
{
m[i][j]=1;
else
m[i][j]=0;
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
printf("%d ",m[i][j]);
printf("\n");
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
if(m[i][j]==1&&m[j][i]==1)
c++;
if(c==n*n1)
else
for(j=0;j<n1;j++)
if(m[i][j]==m[j][i])
if(i==j)
c++;
Output:
Experiment-10
Write a program to implement relational matrix and
check whether it is antisymmetric or not.
#include<stdio.h>
void main()
int a1[100],a2[100],i,j,n,n1,m[100][100],c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a1[i]);
scanf("%d",&n1);
for(j=0;j<n1;j++)
scanf("%d",&a2[j]);
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
if(a1[i]<a2[j]||a1[i]==a2[j])
m[i][j]=1;
}
else
m[i][j]=0;
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
printf("%d ",m[i][j]);
printf("\n");
for(i=0;i<n;i++)
for(j=0;j<n1;j++)
if(m[i][j]==m[j][i])
if(i==j)
c++;
}
if(c==n)
else
Output:
Experiment-11
Write a program to implement prim’s
algorithm(spanning tree).
#include<stdio.h>
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]={0},min,mincost=0,cost[10][10];
void main()
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
visited[1]=1;
printf("\n");
while(ne < n)
for(i=1,min=999;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]< min)
if(visited[i]!=0)
min=cost[i][j];
a=u=i;
b=v=j;
}
if(visited[u]==0 || visited[v]==0)
mincost+=min;
visited[b]=1;
cost[a][b]=cost[b][a]=999;
getch();
Output:
Experiment-12
Write a program implement krushkal’s alogorithm to
find the shortest path.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int i, j, k, a, b, u, v, n, ne = 1;
int find(int);
void main()
printf("========================\n");
scanf("%d", &n);
scanf("%d", &cost[i][j]);
if (cost[i][j] == 0)
cost[i][j] = 999;
{
for (j = 1; j <= n; j++)
min = cost[i][j];
a = u = i;
b = v = j;
u = find(u);
v = find(v);
if (uni(u, v))
mincost += min;
getch();
int find(int i)
while (parent[i])
i = parent[i];
return i;
if (i != j)
{
parent[j] = i;
return 1;
return 0;
Output:
Experimrnt:16
Write a program to implement binomial expansion.
#include<stdio.h>
int factorial(int n)
int f = 1;
f *= i;
return f;
(niFact * iFact) );
int main()
int A = 3, X = 4, n = 5;
series(A, X, n);
return 0;
Output:
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: