Data Structure and Application Lab 2
Data Structure and Application Lab 2
DEPARTMENT OF BIOINFORMATICS
Laboratory Manual
Data Structure and Application Lab
Paper Code: MSBIN 195
List of Assignments
Assignment Name of Experiment Page Date of Grade Signature
No. Number Expt. awarded
1 1. Write a programme to swap two 4-5
variables.
2. Write a programme to convert the
temperature from Fahrenheit to
Celsius.
3. Write a programme to find out
minimum of the two numbers.
3
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 1
1. Write a programme to swap two variables.
Source code
#include<stdio.h>
main() ,
int a;
int b;
printf("enter the numbers\n");
scanf("%d", &a);
scanf("%d", &b);
printf("the number1 is: %d\n", a);
printf("the number2 is: %d\n", b);
a= a+b;
b= a-b;
a= a-b;
printf("after swaspping \n");
printf("the number1 is: %d\n", a);
printf("the number2 is: %d\n", b);
-
Output
scanf("%f",&f);
4
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
c= ((f-32)/9)*5;
printf("the temperature is celcius is: %f",c);
-
Output
5
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 2
4. Write a program to find the net pay of an employee where the basic pay is given from
the user DA Is 12% of the basic salary HRA is the 15% of the basic salary tax is 10% of
the gross salary pf is 2000.
Source code
#include <stdio.h>
int main() ,
double basic, da, hra, tax, gross, net pay;
const double pf = 2000.0;
return 0;
-
Output
6
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
-
Output
d = b * b - 4 * a * c;
if (d > 0)
,
r1 = (-b + sqrt(d)) / (2 * a);
r2 = (-b - sqrt(d)) / (2 * a);
printf("r1 = %.2lf and r2 = %.2lf", r1, r2);
-
else if (d == 0)
,
r1 = r2 = -b / (2 * a);
printf("r1 = r2 = %.2lf", r1);
-
else
,
rp = -b / (2 * a);
ip = sqrt(-d) / (2 * a);
printf("r1 = %.2lf+%.2lfi and r2 = %.2f-%.2fi", rp, ip, rp, ip);
-
return 0;
-
Output
int main() ,
int year;
8
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
if (year % 4 == 0 ) ,
printf("%d is a leap year.\n", year);
- else ,
printf("%d is not a leap year.\n", year);
-
return 0;
-
Output
9
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 3
10.Write a programme to display Fibonacci series.
Source code
#include<stdio.h>
int main()
,
int a=0, b=1,c,n,i;
printf("enter the neumberof terms");
scanf("%d", &n);
printf("%d%d", a,b);
for(i=1; i<=n; i++)
,
c=a+b;
printf("%d",c);
a=b;
b=c;
-
-
Output
int m = a%10;
s=s+ (m*m*m);
a=a/10;
-
if(s==n)
,
printf("it is a armstrong number");
-
else
,
printf("not a armstrong number");
-
-
Output
12
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Source code
#include<stdio.h>
int main()
,
int n, s=0;
printf("Enter the number");
scanf("%d", &n);
while(n>0)
,
int m = n%10;
s=s+m;
n=n/10;
-
printf("the sum of digit is %d", s);
-
Output
14.Write a programme to find the GCD and LCM of the two integer number.
Source code
#include <stdio.h>
int main() ,
int a, b, gcd, lcm, r, n, d;
n = a;
d = b;
while (d != 0) ,
13
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
r = n % d;
n = d;
d = r;
-
gcd = n;
-
Output
14
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 4
Output
b. S= 1-2+3-4+5-………n
Source Code
#include<stdio.h>
int main()
,
int s=0, i=1, n;
printf("Enter the number of terms");
scanf("%d",&n);
for(i=1;i<=n;i++)
,
if(i%2!=0)
,
s=s+i;
-
15
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
else,
s=s-i;
-
-
printf("the sum of the series is %d", s);
-
Output
c. S=2+4+6+8+……….+n
Source Code
#include<stdio.h>
int main()
,
int s=0, i=1, n;
printf("Enter the number of terms");
scanf("%d",&n);
for(i=1;i<=n;i++)
,
if(i%2==0)
,
s=s+i;
-
-
printf("the sum of the series is %d", s);
-
Output
Source code
#include <stdio.h>
16
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
int main() ,
int number, i, prime;
return 0;
-
Output
17
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
int main() ,
int num, originalNum, remainder, result;
while (originalNum != 0) ,
remainder = originalNum % 10;
result += pow(remainder, 3);
originalNum /= 10;
-
if (result == num) ,
printf("%d ", num);
-
-
printf("\n");
return 0;
-
Output
int main() ,
int num, i, sum;
18
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
if (sum == num) ,
printf("%d ", num);
-
-
printf("\n");
return 0;
-
Output
printf("\n");
-
-
Output
b. 1
12
123
1234
12345
Source code
#include<stdio.h>
int main(),
for(int i=1; i<=5; i++)
,
for(int j=1;j<=i; j++)
,
printf("%d",j);
-
printf("\n");
-
-
Output
c. 5555
20
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
4444
333
22
1
Source code
#include<stdio.h>
int main(),
for(int i=5; i>=1; i--)
,
for(int j=1;j<=i; j++)
,
printf("%d",i);
-
printf("\n");
-
-
Output
d. *
***
*****
*******
Source code
#include<stdio.h>
int main(),
for(int i=0; i<=7; i++)
,
for(int j=1;j<=2*i+1; j++)
,
printf("*");
-
21
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
printf("\n");
-
-
Output
e. 1
22
333
4444
55555
Source code
#include<stdio.h>
int main(),
for(int i=1; i<=5; i++)
,
for(int j=1;j<=i; j++)
,
printf("%d",i);
-
printf("\n")
-
-
Output
22
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Source code
20. A)
#include<stdio.h>
int main()
, float n,s=0.0,i,f=1,j=1;
printf("enter value of n:");
scanf("%f",&n);
while(j<=n)
,
for(i=1;i<=n;i++)
,
f=f*i;
-
s=s+i/f;
j++;
-
printf("sum is: %f",s);
-
Output
23
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Source code
B) #include<stdio.h>
void main()
, float n,s=0.0,i,f=1;
printf("enter value of n:");
scanf("%f",&n);
while(n<=5)
,
for(i=1;i<=n;i++)
,
f=f*i;
-
s=s-i/f;
n++;
-
printf("sum is: %f",s);
-
Output
24
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 5
21.Write a programme to find out maximum number among N numbers.
Source code
#include <stdio.h>
int main() ,
int n, i, max;
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
int numbers*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &numbers*i+);
-
max = numbers*0+;
return 0;
-
Output
25
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
22.Write a programme to find out the mean and standard deviation of N numbers.
Source code
#include <stdio.h>
#include <math.h>
int main() ,
int n, i;
float sum = 0.0, mean, standard_deviation = 0.0;
printf("Enter the number of elements: ");
scanf("%d", &n);
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
float numbers*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%f", &numbers*i+);
sum += numbers*i+; // Add to the sum
-
26
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
mean = sum / n;
for (i = 0; i < n; i++) ,
standard_deviation += pow(numbers*i+ - mean, 2);
-
standard_deviation = sqrt(standard_deviation / n);
printf("Mean: %.2f\n", mean);
printf("Standard Deviation: %.2f\n", standard_deviation);
return 0;
-
Output
int main() ,
int n, i, s, f = 0;
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
27
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
int numbers*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &numbers*i+);
-
if (!f) ,
printf("Number %d not found in the array.\n", s);
-
return 0;
-
Output
28
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
int main() ,
int n, i, j, temp, target, low, high, mid, found = 0;
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
int arr*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &arr*i+);
-
for (i = 0; i < n - 1; i++) ,
for (j = 0; j < n - i - 1; j++) ,
if (arr*j+ > arr*j + 1+) ,
temp = arr*j+;
arr*j+ = arr*j + 1+;
arr*j + 1+ = temp;
-
-
-
low = 0;
high = n - 1;
while (low <= high) ,
mid = (low + high) / 2;
if (arr*mid+ == target) ,
printf("Number %d found at position %d (1-based indexing).\n", target, mid + 1);
found = 1;
break;
- else if (arr*mid+ < target) ,
low = mid + 1;
- else ,
high = mid - 1;
-
-
if (!found) ,
printf("Number %d not found in the array.\n", target);
-
return 0;
-
Output
30
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 6
25.Write a programme to sort N number using bubble sort.
Source code
#include <stdio.h>
int main() ,
int n, i, j, temp;
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
int arr*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &arr*i+);
-
printf("\n");
return 0;
-
Output
int main() ,
int n, i, j, key;
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
int arr*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &arr*i+);
-
key = arr*i+;
j = i - 1;
arr*j + 1+ = key;
-
printf("Sorted array: ");
for (i = 0; i < n; i++) ,
printf("%d ", arr*i+);
-
printf("\n");
return 0;
-
Output
33
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
int main() ,
int n, i, j, minIndex, temp;
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
int arr*n+;
printf("Enter %d numbers:\n", n);
for (i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &arr*i+);
-
if (minIndex != i) ,
temp = arr*i+;
arr*i+ = arr*minIndex+;
arr*minIndex+ = temp;
-
-
34
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
return 0;
-
Output
int main() ,
int num;
printf("Enter a number: ");
scanf("%d", &num);
35
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
if (num < 0) ,
printf("Factorial is not defined for negative numbers.\n");
return 1;
-
int fact = factorial(num);
printf("Factorial of %d is %lld\n", num, fact);
return 0;
-
Output
return max;
-
int main() ,
int n;
36
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
if (n <= 0) ,
printf("Invalid number of elements.\n");
return 1;
-
int arr*n+;
printf("Enter %d numbers:\n", n);
for (int i = 0; i < n; i++) ,
printf("Number %d: ", i + 1);
scanf("%d", &arr*i+);
-
int max = findMax(arr, n);
printf("The maximum number is: %d\n", max);
return 0;
-
Output
int main() ,
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num < 0) ,
printf("Factorial is not defined for negative numbers.\n");
return 1;
-
int fact = factorial(num);
printf("Factorial of %d is %d\n", num, fact);
return 0;
-
Output