Professional Documents
Culture Documents
EXNO: 1
DATE:
AIM:
To find subsets from a given sets.
ALGORITHM:
STEP 2: Declare subsets and functions with accept array of element. And convert into
subsets based on index “r”
STEP 4: Get the value for array element one after one
CODING
RESULT:
Thus the above program has been verified and executed successfully.
TRANSITIVE CLOSURE
EX.NO:2
DATE:
AIM:
To write a program to transitive closure
ALGORITHM:
STEP 5:To enter the array values of the set bracket at main function
STEP 7:Print the array values from the main which return values of 0
OUTPUT:
1111
0111
0011
0001
RESULT:
Thus the above program has been verified and executed successfully.
TO PROVE A SERIES
EX.NO: 3
DATE:
AIM:
To find a c program to prove a series 1/ (1*2) + 1/(2*3) ………+1/(n(n+1)) =
n/(n+1) is equal or not.
ALGORITHM:
STEP 4:To using the for loop to calculate the sum. The formula has been
Sum=sum+(1/(i*(i+1).
STEP 5:To declare the values for j. formula has been j=(n/n+1).
CODING:
OUTPUT:
Sum= 0.750000
n(n+1)= 0.750000
the series is equal..
RESULT:
Thus the above program has been verified and executed successfully.
SUM OF THE SERIES
EX.NO:4
DATE:
AIM:
To write a program to perform the sum of series 1+(1+2)+(1+2+3)+...+(1+2+...n)
ALGORITHM:
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,sum=0;
clrscr();
printf("enter the value for n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
sum=sum+j;
}
printf(“\n”);
}
printf("\n the series is =%d", sum);
getch()
}
OUTPUT:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sum:35
RESULT:
Thus the above program has been verified and executed successfully.
FIBONACCI SERIES USING RECURSION
EX.NO:5
DATE:
AIM:
To find the Fibonacci series using recursion method.
ALGORITHM:
CODING:
Prg 5://Fibonacci Series using Recursion
#include <stdio.h>
#include <conio.h>
int fibonacci(int term);
void main(){
int terms, counter;
printf("Enter number of terms in Fibonacci series: ");
scanf("%d", &terms);
printf("Fibonacci series till %d terms\n", terms);
for(counter = 0; counter < terms; counter++){
printf("%d\n", fibonacci(counter));
}
getch(); }
int fibonacci(int term)
{
if(term < 2)
return term;
return fibonacci(term - 1) + fibonacci(term - 2);
}
OUTPUT:
Enter the number of term in Fibonacci series:8
0
1
1
2
3
5
8
13
RESULT:
Thus the above program has been verified and executed successfully.
FACTIORIAL USING IN RECURSION
EX.NO:6
DATE:
AIM:
To find a factorial using recursion method
ALGORITHM:
STEP 2:Declar factorial function with accept n as parameter and return integer values
STEP 3:Get the value for n in the main and call the Function factorial(n);
STEP 5:Factorial function return the values of factorial for Main function
CODING:
Prg 6://Factorial using Recursion
#include <stdio.h>
int factorial(int n);
void main()
{
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);
printf("Factorial of %d = %d", n, factorial(n));
}
int factorial(int n)
{
if (n >= 1)
return n* factorial(n-1);
else
return 1;
}
OUTPUT:
Enter the positive integer:3
Factorial of 3=6
RESULT:
Thus the above program has been verified and executed successfully.
MINIMUM COST SPANNING TREE
EX.NO:7
DATE:
AIM:
To find the program minimum cost spanning tree using Prims algorithm from a graph
ALGORITHM:
STEP 2:Declare the variable array visited two dimensional array cost.minimum cost’0’
STEP 7:Update the maximum cost min=cos[i][j] by visiting the unvisited nodes
STEP 8:Display the edgest with minimum cost and update the minimum path cost
CODING:
0 1 2
2 0 3
3 2 0
Edge 1:(12)cost:1
Edge 2:(13)cost:2
Minimum cost=3
RESULT:
Thus the above program has been verified and executed successfully.
SHORTEST PATH USING DIJKSTRA’S ALGORITHM
EXNO:8
DATE:
AIM:
To find the shortest path of using Dijkstra’s algorithm
ALGORITHM:
STEP 2:Declare the variable and declare DIJKSTRA’S method with cost source and
targets
STEP 5:Find the shortest path from source to target and display the shortest path using
Dijkstra’s Algorithm
CODING:
Prg 8://Shortest path using Dijikstra’s Algorithm
#include<stdio.h>
#include<conio.h>
void main()
{
int path[2][2],i,j,min,a[3][3],p,st=1,ed=3,stp,edp,t[3],index;
clrscr();
printf("enter the cost matrix\n");
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
scanf("%d",&a[i][j]);
printf("enter number of paths\n");
scanf("%d",&p);
printf("enter possible paths\n");
for(i=1;i<=p;i++)
for(j=1;j<=3;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
{
t[i]=0;
stp=st;
for(j=1;j<=3;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
}
min=t[st];index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=3;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}
getch();
}
OUTPUT:
Enter the cost matrix :
005
002
000
enter number of paths : 2
enter possible paths :
12
23
13
minimum cost : 2
minimum cost path :
1–>2–>3
RESULT:
Thus the above program has been verified and executed successfully.
CONSTRUCT THE TRUTH TABLE
EXNO:9
DATE:
AIM:
To construct the truth table using three variables
ALGORITHM:
STEP 2:Declare the 3 variables X,Y,Z and assign the values 0,1
for(x=0;x<=1;++x)
for(y=0;y<=1;++y)
for(z=0;z<=1;++z)
{
if(x*y+z==2)
printf(“\n%d\t%d\t%d\t”,x,y,z);
else
printf(“\n%d\t%d\t%d\t%d”,x,y,z,x*y+z);
}
getch();
}
OUTPUT:
X Y Z XY+Z
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 _
RESULT:
Thus the above program has been verified and executed successfully
DEMORGAN’S LAW
EX.NO:10
DATE:
AIM:
To prove the Demorgan’s Law
ALGORITHM:
STEP 4:To prove the program DEMORGAN’S LAW using the formula:
If((!(x<5)&&!(y>=7))&&!((x<5)!!(y>=7)))
STEP 5:For values x>5 and then y<7 the expression is executed for truth table
STEP 6:For values x<5 and then y>7 the expression is executed for the truth table
CODING:
Prg 10://To Prove De- Morgan’s Law
#include <stdio.h>
#include <math.h>
int main()
{
int x;
int y;
printf("Enter x: ");
scanf("%d",&x);
printf("Enter y: ");
scanf("%d",&y);
if ((!(x < 3) && !(y >= 7)) && !((x < 3) || (y >= 7)))
{
printf("True!\n\n");
}
else
{
printf("False!\n\n");
}
}
OUTPUT:
Enter X=6
Enter y=6
TRUE!!!!!
Enter X=7
Enter y=4
FALSE!!!!!
RESULT:
Thus the above program has been verified and executed successfully