DS LaqReport
DS LaqReport
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
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
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
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");
}
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.