Add Q1.c
This commit is contained in:
41
Q1.c
Normal file
41
Q1.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct Student {
|
||||
int id;
|
||||
char name[30];
|
||||
double grade;
|
||||
} Student;
|
||||
|
||||
typedef struct Node {
|
||||
Student student;
|
||||
struct Node* next;
|
||||
} Node;
|
||||
|
||||
Node* newNode(const int id, const char* name, const double grade) {
|
||||
Node* node = (Node*)malloc(sizeof(Node));
|
||||
node->student.id = id;
|
||||
strcpy(node->student.name, name);
|
||||
node->student.grade = grade;
|
||||
node->next = NULL;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
void printStudents(Node* head) {
|
||||
Node* current = head;
|
||||
while (current != NULL) {
|
||||
printf("Student ID: %d\n", current->student.id);
|
||||
printf("Student Name: %s\n", current->student.name);
|
||||
printf("Student Grade: %f\n", current->student.grade);
|
||||
current = current->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user