An array of structure is used to store multiple employee records. We can apply conditions on structure members to display only specific records according to the given requirement.
In this program, employee details such as employee id, name, and salary are stored using an array of structures. The program checks the salary of each employee and displays only those employees whose salary is greater than 15000.
How It Works?
employee with members id, name, and salary.e[5] to store multiple employee records.for loop.for loop to check each employee's salary.#include <stdio.h> #include <conio.h> struct employee { char name[20]; int id, salary; }; main() { struct employee e[5]; int k; clrscr(); for(k = 0; k <= 2; k++) { printf("Enter the Employee Id : "); scanf("%d", &e[k].id); printf("Enter the Employee Name : "); scanf("%s", e[k].name); printf("Enter the Employee Salary : "); scanf("%d", &e[k].salary); } printf("\nId \tName \tSalary"); for(k = 0; k <= 2; k++) { if(e[k].salary > 15000) { printf("\n%d", e[k].id); printf("\t%s", e[k].name); printf("\t%d", e[k].salary); } } getch(); }
array of structure to store details of 5 employees and display only those employees whose salary is greater than 50000.employee with members id, name, and salary. Store employee records using an array of structures. Use an if condition to check whether salary > 50000 before displaying employee details.
#include <stdio.h> #include <conio.h> struct employee { char name[20]; int id, salary; }; main() { struct employee e[5]; int k; clrscr(); for(k = 0; k <= 2; k++) { printf("Enter Employee Id : "); scanf("%d", &e[k].id); printf("\nEnter Employee Name : "); scanf("%s", e[k].name); printf("\nEnter Employee Salary : "); scanf("%d", &e[k].salary); } printf("\nId \tName \tSalary"); for(k = 0; k <= 2; k++) { if(e[k].salary > 50000) { printf("\n%d", e[k].id); printf("\t%s", e[k].name); printf("\t%d", e[k].salary); } } getch(); }
if condition. Only employees having salary greater than 50000 are displayed.