luc082.c (1351B)
1 /* Structure 'employee' (Code, Name, Date of Joining). Display names of employees with tenure >= 3 years. 2 */ 3 /* Let Us C, Chap- 17 (Structures), Qn No.: B(e) */ 4 5 /* This file is auto-generated by a bot. */ 6 /* This code is not compiled; it is for reference only. */ 7 8 9 #include <stdio.h> 10 #include <string.h> 11 #include <stdlib.h> 12 13 struct date 14 { 15 int day; 16 int month; 17 int year; 18 }; 19 20 struct employee 21 { 22 int code; 23 char name[30]; 24 struct date doj; 25 }; 26 27 int main() 28 { 29 struct employee emp[5] = { 30 {101, "Amit", {12, 1, 2020}}, 31 {102, "Sumit", {15, 8, 2023}}, 32 {103, "Rina", {1, 1, 2018}}, 33 {104, "Tina", {20, 5, 2022}}, 34 {105, "Mina", {10, 12, 2025}} 35 }; 36 int n = 5, i; 37 struct date current; 38 39 printf("Enter current date (dd mm yyyy): "); 40 scanf("%d %d %d", ¤t.day, ¤t.month, ¤t.year); 41 42 printf("\nEmployees with tenure >= 3 years:\n"); 43 for (i = 0; i < n; i++) 44 { 45 int years = current.year - emp[i].doj.year; 46 47 // Adjust for month/day 48 if (current.month < emp[i].doj.month || 49 (current.month == emp[i].doj.month && current.day < emp[i].doj.day)) 50 { 51 years--; 52 } 53 54 if (years >= 3) 55 { 56 printf("%s (Tenure: %d years)\n", emp[i].name, years); 57 } 58 } 59 60 return 0; 61 }