/* * Author : Amit Dutta * Date : 08 Feb 2026 * Repo : https://github.com/notamitgamer/bsc * License : MIT License (See the LICENSE file for details) */ /* Create a structure 'student' (Roll, Name, Dept, Course, Year). Write functions to print names by join year and print data by roll number. */ /* Let Us C, Chap- 17 (Structures), Qn No.: B(a) */ /* This file is auto-generated by a bot. */ /* This code is not compiled; it is for reference only. */ #include #include #include struct student { int roll; char name[50]; char dept[20]; char course[20]; int year; }; void print_by_year(struct student *s, int n, int year); void print_by_roll(struct student *s, int n, int roll); int main() { struct student data[450] = { {101, "Amit", "CS", "B.Sc", 2024}, {102, "Rahul", "Physics", "B.Sc", 2024}, {103, "Sneha", "CS", "M.Sc", 2023}, {104, "Priya", "Maths", "B.Sc", 2025}, {105, "Rohan", "CS", "B.Sc", 2024} }; int n = 5; // Using 5 sample records int year, roll; printf("Enter year to list students: "); scanf("%d", &year); print_by_year(data, n, year); printf("\nEnter roll number to find student: "); scanf("%d", &roll); print_by_roll(data, n, roll); return 0; } void print_by_year(struct student *s, int n, int year) { int i, found = 0; printf("Students joining in %d:\n", year); for (i = 0; i < n; i++) { if (s[i].year == year) { printf("- %s\n", s[i].name); found = 1; } } if (!found) printf("No students found for this year.\n"); } void print_by_roll(struct student *s, int n, int roll) { int i; for (i = 0; i < n; i++) { if (s[i].roll == roll) { printf("\n--- Student Details ---\n"); printf("Roll: %d\nName: %s\nDept: %s\nCourse: %s\nYear: %d\n", s[i].roll, s[i].name, s[i].dept, s[i].course, s[i].year); return; } } printf("Student with Roll %d not found.\n", roll); }