Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/week4_2_struct_student.c
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
/*
* week4_2_struct_student.c
* Author: [Your Name]
* Student ID: [Your ID]
* Author: Mehmet Taha Ünal
* Student ID: 231AMB077
* Description:
* Demonstrates defining and using a struct in C.
* Students should define a 'Student' struct with fields like name, id, and grade.
* Then create a few instances and print them.
* Demonstrates defining and using a struct in C.
* Defines a 'Student' struct with name, id, and grade fields,
* creates two Student variables, assigns values, and prints them.
*/

#include <stdio.h>
#include <string.h>

// TODO: Define struct Student with fields: name (char[]), id (int), grade (float)
// Example:
// struct Student {
// char name[50];
// int id;
// float grade;
// };
// Define struct Student
struct Student {
char name[50];
int id;
float grade;
};

int main(void) {
// TODO: Declare one or more Student variables
struct Student s1, s2;

// TODO: Assign values (either manually or via scanf)
// Assign values manually
strcpy(s1.name, "Defne Goker");
s1.id = 1001;
s1.grade = 9.1f;

// TODO: Print struct contents using printf
strcpy(s2.name, "Emir Olgun");
s2.id = 1002;
s2.grade = 8.7f;

// Print results
printf("Student 1: %s, ID: %d, Grade: %.1f\n", s1.name, s1.id, s1.grade);
printf("Student 2: %s, ID: %d, Grade: %.1f\n", s2.name, s2.id, s2.grade);

return 0;
}