Maulana Abul Kalam Azad University of Technology, West Bengal
DEPARTMENT OF BIOINFORMATICS
Laboratory Manual
Data Structure and Application Lab
Paper Code: MSBIN 195
For M.Sc. in Bioinformatics
1st Semester
2024-25
Name: Soumyajit Dutta
University Roll No:
Year: 1st Semester: 1st
Session: 2024-25
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
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.
2 4. Write a program to find the net pay of 6-10
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.
5. Write a programme to check whether
the given number is even or odd.
6. Write a programme to find out real
roots of quadratic equation.
7. Write a programme to check a year is
leap year or not.
8. Write a programme to find out the
factorial of given integer number.
9. Write a programme to print all odd
numbers from 10 to 100.
3 10. Write a programme to display 11-14
Fibonacci series.
11. Write a programme to check whether
the number is Armstrong number or
not.
12. Write a programme to find out
number of digits in a given number.
13. Write a programme to find out the
sum of digits of a given integer.
14. Write a programme to find the GCD
and LCM of the two integer number.
4 15. Write a programme to perform the 15-24
following: a. S=1+2+3+4+5+…..+n b.
S= 1-2+3-4+5-………n c.
S=2+4+6+8+……….+n
16. Write A programme to print all the
prime numbers from 50 to 100.
17. Write a programme to print all
Armstrong numbers from 100 to
1000.
18. Write a programme to print all perfect
numbers from 1 to 100
19. Write a programme to perform the
following:a. * b. 1 c. 1 d. * e.55555 *
12 22 ** 4444 * 123 333 *** 333 **
1234 4444 *** 22 ** 12345 55555
**** 1
20. Write a programme to perform the
2
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
following: a. S = 1+ 2/2! + 3/3! + 4/4!
+ …………. Nth terms b. S = 1- 2/2!
+ 3/3! - 4/4! + …………. Nth terms
5 21. Write a programme to find out 24-30
maximum number among N numbers.
22. Write a programme to find out the
mean and standard deviation of N
numbers.
23. Write a programme to find a number
among N numbers using linear
search.
24. Write a programme to find a number
among N numbers using binary
search.
6 25. Write a programme to sort N number 31-38
using bubble sort.
26. Write a programme to sort N number
using selection sort.
27. Write a programme to sort N number
using insertion sort.
28. Write a programme to find the
factorial of a number using function.
29. Write a programme to find maximum
number using function among N
numbers.
30. Write a programme to find the
factorial of a number using recursion.
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
2. Write a programme to convert the temperature from Fahrenheit to Celsius.
Source code
#include<stdio.h>
main() ,
float c;
float f;
printf("enter the temperature in farenhite \n");
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
3. Write a programme to find out minimum of the two numbers.
Source code
#include<stdio.h>
int main()
,
int a,b;
printf("enter two numbers\t");
scanf("%d %d", &a, &b);
if(a<b)
printf("%d is minumum",a);
else
printf("%d is minumum",b);
-
Output
Teacher’s signature with date …………………..
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;
printf("Enter the basic pay of the employee: ");
scanf("%lf", &basic);
da = 0.12 * basic;
hra = 0.15 * basic;
gross = basic + da + hra;
tax = 0.10 * gross;
net_pay = gross - tax - pf;
printf("\n--- Salary Details ---\n");
printf("Basic Pay: %.2lf\n", basic);
printf("DA (12%%): %.2lf\n", da);
printf("HRA (15%%): %.2lf\n", hra);
printf("Gross Salary: %.2lf\n", gross);
printf("Tax (10%% of Gross): %.2lf\n", tax);
printf("Provident Fund (PF): %.2lf\n", pf);
printf("Net Pay: %.2lf\n", net_pay);
return 0;
-
Output
6
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
5. Write a programme to check whether the given number is even or odd.
Source code
#include<stdio.h>
main() ,
int a ,i;
printf("enter the number to be checked\n");
scanf("%d", &a);
if(a%2==0)
printf("%d is a even number\n", a);
else
printf("%d is a odd number\n", a);
-
Output
6. Write a programme to find out real roots of quadratic equation.
Source code
#include<math.h>
#include <stdio.h>
int main() ,
double a, b, c, d, r1, r2, rp, ip;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf", &a, &b, &c);
7
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
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
7. Write a programme to check a year is leap year or not.
Source code
#include <stdio.h>
int main() ,
int year;
printf("Enter a year: ");
scanf("%d", &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
8. Write a programme to find out the factorial of given integer number.
Source code
#include<stdio.h>
int main()
,
int a;
int fact=1;
printf("enter the number");
scanf("%d",&a);
int i=1;
while(i<=a)
,
fact= fact*i;
i=i+1;
-
printf("the factorial of %d is %d", a, fact);
-
Output
9
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
9. Write a programme to print all odd numbers from 10 to 100.
Source code
#include<stdio.h>
int main()
,
for(int i=10; i<=100; i++)
,
if(i%2!=0)
,
printf("odd number %d\n",i);
-
else
,
printf("not odd number %d\n",i);
-
-
-
Output
Teacher’s signature with date …………………..
10
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
11.Write a programme to check whether the number is Armstrong number or not.
Source code
#include<stdio.h>
int main()
,
int n, s=0;
printf("enter the number to checked");
scanf("%d", &n);
int a = n;
while(a!=0)
,
11
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
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.Write a programme to find out number of digits in a given number.
Source code
#include<stdio.h>
int main()
,
int n, c=0;
printf("enter the number");
scanf("%d",&n);
while (n>0)
,
n=n/10;
c++;
-
printf("%d", c);
-
Output
12
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
13.Write a programme to find out the sum of digits of a given integer.
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;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
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;
lcm = (a * b)/ gcd;
printf("GCD of %d and %d is: %d\n", a, b, gcd);
printf("LCM of %d and %d is: %d\n", a, b, lcm);
-
Output
Teacher’s signature with date …………………..
14
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
Assignment No: 4
15.Write a programme to perform the following:
a. S=1+2+3+4+5+…..+n
Source code
#include<stdio.h>
int main()
,
int s= 0;
int i=1;
int n;
printf("enter the number of terms");
scanf("%d",&n);
for(i=1;i<=n;i++)
,
s=s+i;
-
printf("the sum of the series is %d", s);
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
16.Write A programme to print all the prime numbers from 50 to 100.
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;
printf("Prime numbers between 50 and 100:\n");
for (number = 50; number <= 100; number++) ,
prime= 1;
for (i = 2; i < number; i++) ,
if (number % i == 0) ,
prime= 0;
break;
-
-
if (prime) ,
printf("%d\n", number);
-
-
return 0;
-
Output
17.Write a programme to print all Armstrong numbers from 100 to 1000.
#include <stdio.h>
#include <math.h>
17
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
int main() ,
int num, originalNum, remainder, result;
printf("Armstrong numbers between 100 and 1000:\n");
for (num = 100; num <= 1000; num++) ,
originalNum = num;
result = 0;
while (originalNum != 0) ,
remainder = originalNum % 10;
result += pow(remainder, 3);
originalNum /= 10;
-
if (result == num) ,
printf("%d ", num);
-
-
printf("\n");
return 0;
-
Output
18.Write a programme to print all perfect numbers from 1 to 100.
Source code
#include <stdio.h>
int main() ,
int num, i, sum;
printf("Perfect numbers between 1 and 100:\n");
18
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
for (num = 1; num <= 100; num++) ,
sum = 0;
for (i = 1; i <= num / 2; i++) ,
if (num % i == 0) ,
sum += i;
-
-
if (sum == num) ,
printf("%d ", num);
-
-
printf("\n");
return 0;
-
Output
19.Write a programme to perform the following:
a. *
**
***
****
*****
Source code
#include<stdio.h>
int main(),
for(int i=1; i<=5; i++)
,
for(int j=1;j<=i; j++)
,
printf("*");
-
19
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
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
20.Write a programme to perform the following:
a. S = 1+ 2/2! + 3/3! + 4/4! + …………. Nth terms
Source code
b. S = 1- 2/2! + 3/3! - 4/4! + …………. Nth terms
Source code
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;
printf("Enter the number of elements: ");
scanf("%d", &n);
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+;
for (i = 1; i < n; i++) ,
if (numbers*i+ > max) ,
max = numbers*i+;
-
-
printf("The maximum number is: %d\n", max);
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
23.Write a programme to find a number among N numbers using linear search.
Source code
#include <stdio.h>
int main() ,
int n, i, s, f = 0;
printf("Enter the number of elements: ");
scanf("%d", &n);
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+);
-
printf("Enter the number to search: ");
scanf("%d", &s);
for (i = 0; i < n; i++) ,
if (numbers*i+ == s) ,
printf("Number %d found at position %d.\n", s, i + 1);
f = 1;
break;
-
-
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
24.Write a programme to find a number among N numbers using binary search.
Source code
#include <stdio.h>
int main() ,
int n, i, j, temp, target, low, high, mid, found = 0;
printf("Enter the number of elements: ");
scanf("%d", &n);
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;
-
-
-
printf("Sorted array: ");
for (i = 0; i < n; i++) ,
printf("%d ", arr*i+);
-
printf("\n");
29
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
printf("Enter the number to search: ");
scanf("%d", &target);
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;
printf("Enter the number of elements: ");
scanf("%d", &n);
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;
-
-
-
printf("Sorted array: ");
for (i = 0; i < n; i++) ,
printf("%d ", arr*i+);
-
31
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
printf("\n");
return 0;
-
Output
26.Write a programme to sort N number using insertion sort.
Source code
#include <stdio.h>
int main() ,
int n, i, j, key;
printf("Enter the number of elements: ");
scanf("%d", &n);
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 = 1; i < n; i++) ,
32
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
key = arr*i+;
j = i - 1;
while (j >= 0 && arr*j+ > key) ,
arr*j + 1+ = arr*j+;
j--;
-
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
27.Write a programme to sort N number using selection sort.
Source code
#include <stdio.h>
int main() ,
int n, i, j, minIndex, temp;
printf("Enter the number of elements: ");
scanf("%d", &n);
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++) ,
minIndex = i;
for (j = i + 1; j < n; j++) ,
if (arr*j+ < arr*minIndex+) ,
minIndex = j;
-
-
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
printf("Sorted array: ");
for (i = 0; i < n; i++) ,
printf("%d ", arr*i+);
-
printf("\n");
return 0;
-
Output
28.Write a programme to find the factorial of a number using function.
Source code
#include <stdio.h>
int factorial(int n) ,
int fact = 1;
for (int i = 1; i <= n; i++) ,
fact *= i;
-
return fact;
-
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
29.Write a programme to find maximum number using function among N numbers.
Source code
#include <stdio.h>
int findMax(int arr*+, int n) ,
int max = arr*0+;
for (int i = 1; i < n; i++) ,
if (arr*i+ > max) ,
max = arr*i+;
-
-
return max;
-
int main() ,
int n;
36
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
printf("Enter the number of elements: ");
scanf("%d", &n);
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
30.Write a programme to find the factorial of a number using recursion.
Source code
#include <stdio.h>
int factorial(int n) ,
if (n == 0 || n == 1) ,
return 1;
- else ,
return n * factorial(n - 1);
-
37
Data Structure and Application Lab (MSBIN195)
Maulana Abul Kalam Azad University of Technology, West Bengal
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
Teacher’s signature with date …………………..
38