Data sturcture and algorithm week 3
Data sturcture and algorithm week 3
Semester – II Semester
EA2331201010152
1. Write a C program that allocates sufficient memory for processing n
students data. The student details like Register number, name,
semester, 5 course codes along with their respective marks need to
be read as input. Generate a report with register number and grades
for all the courses, with appropriate headers. Note: Use meaningful
names for variables, Include proper documentation, Store the data
using linked representation of list.
Ans. C program that allocates memory for processing n students' data using a linked list
representation, reads their details, and generates a report:
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Function prototypes
Student* create_student_node(int reg_number, char name[], int semester, char
course_codes[][10], int marks[]);
void add_student(Student** head_ptr, Student* new_student);
void print_report(Student* head);
int main() {
int n, i;
Student* head = NULL; // Head pointer of the student linked list
EA2331201010152
}
// Free the allocated memory for the student list (implementation left as an
exercise)
// ... (code to free memory for each student node)
return 0;
}
new_student->reg_number = reg_number;
strcpy(new_student->name, name);
new_student->semester = semester;
memcpy(new_student->course_codes, course_codes, sizeof(course_codes)); // Copy course
codes array
memcpy(new_student->marks, marks, sizeof(marks)); // Copy marks array
new_student->next = NULL;
return new_student;
}
EA2331201010152