1. Student Record Management System
Program Description: Stores and displays multiple student records using array of structures.
#include <stdio.h>
#include <string.h>
typedef struct {
int id;
char name[50];
float marks;
} Student;
int main() {
int n;
printf("Enter number of students: ");
scanf("%d", &n);
Student students[n];
// Input student details
for(int i = 0; i < n; i++) {
printf("\nEnter ID, Name, Marks for student %d: ", i+1);
scanf("%d", &students[i].id);
scanf(" %[^\n]", students[i].name); // input string with spaces
scanf("%f", &students[i].marks);
}
// Display student details
printf("\nStudent Records:\n");
for(int i = 0; i < n; i++) {
printf("ID: %d, Name: %s, Marks: %.2f\n",
students[i].id, students[i].name, students[i].marks);
}
return 0;
}
Sample Output:
Enter number of students: 2
Enter ID, Name, Marks for student 1: 101 Muni 95.5
Enter ID, Name, Marks for student 2: 102 Pooja 88.0
Student Records:
ID: 101, Name: Muni, Marks: 95.50
ID: 102, Name: Pooja, Marks: 88.00
2. Employee Database
Program Description: Stores multiple employee records including nested structure for date of joining.
#include <stdio.h>
#include <string.h>
typedef struct {
int day, month, year;
} Date;
typedef struct {
int empId;
char name[50];
float salary;
Date doj; // date of joining
} Employee;
int main() {
int n;
printf("Enter number of employees: ");
scanf("%d", &n);
Employee emp[n];
// Input employee details
for(int i = 0; i < n; i++) {
printf("\nEnter ID, Name, Salary: ");
scanf("%d", &emp[i].empId);
scanf(" %[^\n]", emp[i].name);
scanf("%f", &emp[i].salary);
printf("Enter Date of Joining (DD MM YYYY): ");
scanf("%d %d %d", &emp[i].doj.day, &emp[i].doj.month, &emp[i].doj.year);
}
// Display employee details
printf("\nEmployee Database:\n");
for(int i = 0; i < n; i++) {
printf("ID: %d, Name: %s, Salary: %.2f, DOJ: %02d-%02d-%04d\n",
emp[i].empId, emp[i].name, emp[i].salary,
emp[i].doj.day, emp[i].doj.month, emp[i].doj.year);
}
return 0;
}
Sample Output:
Enter number of employees: 2
Enter ID, Name, Salary: 101 Muni 50000
Enter Date of Joining (DD MM YYYY): 15 12 2020
Enter ID, Name, Salary: 102 Pooja 45000
Enter Date of Joining (DD MM YYYY): 01 01 2021
Employee Database:
ID: 101, Name: Muni, Salary: 50000.00, DOJ: 15-12-2020
ID: 102, Name: Pooja, Salary: 45000.00, DOJ: 01-01-2021
Key Points to Remember
- Use typedef to simplify structure names
- Use array of structures to store multiple records
- Nested structures help store related complex data (like date of joining)
- Always handle string input carefully to include spaces
- Useful for student management, employee databases, and real-world applications