Discrete Structure Lab Questions
PROGRAMS
1. C program to demonstrate example of floor and ceil functions.
Output
Enter a float value: 123.45
floor value:123.000000
ceil value:124.000000
2.What is cartesian product of two set:-
if set A={1,2} and set B={4,5,6,7} then cartesian product of set A and B is :-
A*B={ (1,4),(1,5),(1,6),(1,7),(2,4),(2,5),(2,6),(2,7) }
Program:-
Output:-
Enter size of set A
2
Enter element of set A
1 2
Enter size of set B
4
Enter element of set B
4 5 6 7
{ (1,4),(1,5),(1,6),(1,7),(2,4),(2,5),(2,6),(2,7) }
3.Perform addition, subtraction, multiplication and division of two numbers
Sample Output:
Input any two numbers separated by comma : 10,5
The sum of the given numbers : 15
The difference of the given numbers : 5
The product of the given numbers : 50
The quotient of the given numbers : 2.000000
MODULUS = 0
4.The C program for the permutation of numbers is given below.
#include <stdio.h>
#include <conio.h>
int fact(int);
int main()
{
int NPR,N,R,M,i;
NPR=0;
M=0;
M= N-R;
printf("Enter value for N and R:");
scanf("%d %d",&N,&R);
NPR = fact(N)/fact(M);
for(i=0;i<45;i++)
printf("_");printf("\n\n");
printf("Number of %d-permutation of %d object
= %dn",R,N,NPR);
for(i=0;i<45;i++)
printf("_");printf("\n\n");
system("PAUSE");
return 0;
}
int fact(m)
{
int i,fact=1;
for(i=1;i<=m;i++)
{
fact=fact*i;
}
return(fact);
}
Output
The output of the first program is given below.
Enter value for N and R: 10 2
------------------------------------------------
Number of 2-permutation of 10 objects = 3628800
5.C program to demonstrate Basic Euclidean Algorithm
Output
gcd(60, 25) = 5