0% found this document useful (0 votes)
11 views

DS LaqReport

This lab report describes two experiments with C programs. The first program demonstrates basic array operations like insertion, searching, and deletion. It takes user input to update and print an integer array. The second program uses a structure to store student data like name, ID, and section. It allocates memory dynamically and inputs information for multiple students before printing the collected details.

Uploaded by

Avro Abir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

DS LaqReport

This lab report describes two experiments with C programs. The first program demonstrates basic array operations like insertion, searching, and deletion. It takes user input to update and print an integer array. The second program uses a structure to store student data like name, ID, and section. It allocates memory dynamically and inputs information for multiple students before printing the collected details.

Uploaded by

Avro Abir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

LAB REPORT-1

Course Code : CSE-135


Course Title : Data Structure Lab

Submitted To :
Md. Mubtasim Fuad
Lecturer, Dept. of CSE
Daffodil International University

Submitted By :
Name :Abir Hossain
ID : 221-15-5766
Section : 61_T
Daffodil International University

Submission Date : 28-8-2023


Experiment No:1
Experiment Name: Implementation of Basic Array Operations in C.
#include <stdio.h>
int size;
void printArray(int ar[], int n)
{
for(int i = 0; i < n; i++)
{
printf("%i ", ar[i]);
}
printf("\n");
}
void insertAtEnd(int* A, int element)
{
A[size] = element;
size++;
}
void searchElement(int ar[], int searchKey)
{
for(int i = 0; i < size; i++)
{
if(ar[i] == searchKey)
{
printf("Element Found at index %d\n", i);
return;
}
}
printf("Element Not Found\n");
}

void deleteElement(int* ar, int index)


{
for(int i = index; i < size - 1; i++)
{
ar[i] = ar[i+1];
}
size--;
}

int main()
{
int ar[10] = {1, 2, 3, 4};
size = 8;

printf("Elements at beginning:\n");
printArray(ar, size);

int value;
printf("Enter a value:\n");
scanf("%d", &value);
insertAtEnd(ar, value);
printArray(ar, size);

int searchValue;
printf("Enter the value to be searched:\n");
scanf("%d", &searchValue);
searchElement(ar, searchValue);

int index;
printf("Enter the index from where you want to delete the value:\n");
scanf("%d", &index);
deleteElement(ar, index);
printArray(ar, size);

}
Discussion:
This code is a simple C program that demonstrates basic array operations. I make
various array operations to insert an element at the end of an array, search for an
element in the array, and delete an element from a specific index using function.
I have initialized an array `ar` with 10 elements and set the variable `size` to 8 as
global value. I take user inputs to print the array's initial elements.
In printArray function I just print array value using loop which is then inserted at
the end of the array using the `insertAtEnd` function.
Subsequently, I use loop to compare every array value with the search key. The
`searchElement` function searches for the value and prints its index if found, or a
message if not found.
Lastly, I am asked to input an index for deletion. The `deleteElement` function
removes the element at that index by shifting the subsequent elements to the left.
The updated array is printed once again.
LAB REPORT-2

Course Code : CSE-135


Course Title : Data Structure Lab

Submitted To :
Md. Mubtasim Fuad
Lecturer, Dept. of CSE
Daffodil International University

Submitted By :
Name :Abir Hossain
ID : 221-15-5766
Section : 61_T
Daffodil International University

Submission Date : 28-8-2023


Experiment No:2
Experiment Name: Experiment Name: A program to store student information
using structures in C
#include <stdio.h>
#include<stdlib.h>

typedef struct Student {


char name[20];
int Id;
char section;
}Student;

int main()
{
int n;
printf("Enter the number of students:\n");
scanf("%d", &n);
Student *s = (Student*) calloc(n, sizeof(Student));
for(int i = 0; i < n; i++) {
printf("Enter information for student %d:\n", i + 1);
printf("Enter Name: ");
scanf(" %[^\n]", s[i].name);
printf("Enter Id: ");
scanf("%d", &s[i].Id);
printf("Enter Section: ");
scanf(" %[^\n]", &s[i].section);
printf("\n");
}

printf("\n\nStudent Information: \n");


for(int i = 0; i < n; i++) {
printf("Student %d Name: %s\n", i+1, s[i].name);
printf("Student %d Id: %d\n", i+1, s[i].Id);
printf("Student %d Section: %c\n", i+1, s[i].section);
printf("\n");
}

return 0;
Discussion:
I create a `Student` structure containing attributes like name, ID, and section. It
contains information for each student, including their name, ID, and section by
using a loop and `scanf` statements. The information is stored in the allocated
memory.
After gathering the student information, the program displays the collected details
for each student using another loop. It prints the name, ID, and section of each
student in a structured manner.
In summary, this code dynamically manages student information by using memory
allocation and the `Student` structure. It provides a basic framework for storing
and displaying student data.

You might also like