diff --git a/src/week4_2_struct_student.c b/src/week4_2_struct_student.c index b04fc32..04948ce 100644 --- a/src/week4_2_struct_student.c +++ b/src/week4_2_struct_student.c @@ -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 #include -// 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; }