An array of structure is used to store multiple student records. We can apply conditions on structure members to display only specific records according to the given requirement.
In this program, student details such as name, roll number, and fees are stored using an array of structures. The program checks the fees of each student and displays only those students whose fees are greater than 500.
How It Works?
student with members name, rollno, and fees.s[5] to store multiple student records.for loop.for loop to check each student's fees.#include <stdio.h> #include <conio.h> struct student { char name[20]; int rollno, fees; }; main() { struct student s[5]; int k; clrscr(); for(k = 0; k <= 2; k++) { printf("Enter the student Name : "); scanf("%s", s[k].name); printf("\nEnter the Roll Number : "); scanf("%d", &s[k].rollno); printf("\nEnter the fees : "); scanf("%d", &s[k].fees); } printf("\nName \tRoll No. \tFees"); for(k = 0; k <= 2; k++) { if(s[k].fees > 500) { printf("\n%s", s[k].name); printf("\t%d", s[k].rollno); printf("\t%d", s[k].fees); } } getch(); }
array of structure to store details of 5 employees and display only those employees whose salary is greater than 30000.employee with members name, id, and salary. Accept multiple employee records using an array of structures. Use an if condition to check whether salary > 30000 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 Name : "); scanf("%s", e[k].name); printf("\nEnter Employee ID : "); scanf("%d", &e[k].id); printf("\nEnter Salary : "); scanf("%d", &e[k].salary); } printf("\nName \tID \tSalary"); for(k = 0; k <= 2; k++) { if(e[k].salary > 30000) { printf("\n%s", e[k].name); printf("\t%d", e[k].id); printf("\t%d", e[k].salary); } } getch(); }
if condition. Only employees having salary greater than 30000 are displayed.