luc078.c (2133B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Create a structure 'student' (Roll, Name, Dept, Course, Year). Write functions to print names by join year and print data by roll number. 9 */ 10 /* Let Us C, Chap- 17 (Structures), Qn No.: B(a) */ 11 12 /* This file is auto-generated by a bot. */ 13 /* This code is not compiled; it is for reference only. */ 14 15 16 #include <stdio.h> 17 #include <string.h> 18 #include <stdlib.h> 19 20 struct student 21 { 22 int roll; 23 char name[50]; 24 char dept[20]; 25 char course[20]; 26 int year; 27 }; 28 29 void print_by_year(struct student *s, int n, int year); 30 void print_by_roll(struct student *s, int n, int roll); 31 32 int main() 33 { 34 struct student data[450] = { 35 {101, "Amit", "CS", "B.Sc", 2024}, 36 {102, "Rahul", "Physics", "B.Sc", 2024}, 37 {103, "Sneha", "CS", "M.Sc", 2023}, 38 {104, "Priya", "Maths", "B.Sc", 2025}, 39 {105, "Rohan", "CS", "B.Sc", 2024} 40 }; 41 int n = 5; // Using 5 sample records 42 int year, roll; 43 44 printf("Enter year to list students: "); 45 scanf("%d", &year); 46 print_by_year(data, n, year); 47 48 printf("\nEnter roll number to find student: "); 49 scanf("%d", &roll); 50 print_by_roll(data, n, roll); 51 52 return 0; 53 } 54 55 void print_by_year(struct student *s, int n, int year) 56 { 57 int i, found = 0; 58 printf("Students joining in %d:\n", year); 59 for (i = 0; i < n; i++) 60 { 61 if (s[i].year == year) 62 { 63 printf("- %s\n", s[i].name); 64 found = 1; 65 } 66 } 67 if (!found) printf("No students found for this year.\n"); 68 } 69 70 void print_by_roll(struct student *s, int n, int roll) 71 { 72 int i; 73 for (i = 0; i < n; i++) 74 { 75 if (s[i].roll == roll) 76 { 77 printf("\n--- Student Details ---\n"); 78 printf("Roll: %d\nName: %s\nDept: %s\nCourse: %s\nYear: %d\n", 79 s[i].roll, s[i].name, s[i].dept, s[i].course, s[i].year); 80 return; 81 } 82 } 83 printf("Student with Roll %d not found.\n", roll); 84 }