C Program to Store and Display Records of N Employees Using Structure (स्ट्रक्चर का उपयोग करके N एम्प्लोयी के रिकार्ड्स स्टोर और डिस्प्ले करना)
In C language, an array of structures is used to store and manage records of multiple employees. Each employee record contains employee ID, name, designation, address, mobile number, gender and salary.
C Language में Multiple Employees के Records को Store और Manage करने के लिए Array of Structures का उपयोग किया जाता है। प्रत्येक Employee के Record में ID, Name, Designation, Address, Mobile Number, Gender और Salary शामिल होते हैं।
C Program
#include <stdio.h>#include <string.h>#define N 10struct employee{int eid;char ename[20];char des[20];char add[50];char mobile[14];char gender;float salary;};int main(){int i;struct employee emp[N];// Input employee recordsfor (i = 0; i < N; i++){printf("\nEnter details of Employee %d:\n", i + 1);printf("Enter employee ID: ");scanf("%d", &emp[i].eid);getchar();printf("Enter employee name: ");fgets(emp[i].ename, sizeof(emp[i].ename), stdin);emp[i].ename[strcspn(emp[i].ename, "\n")] = '\0';printf("Enter designation: ");fgets(emp[i].des, sizeof(emp[i].des), stdin);emp[i].des[strcspn(emp[i].des, "\n")] = '\0';printf("Enter address: ");fgets(emp[i].add, sizeof(emp[i].add), stdin);emp[i].add[strcspn(emp[i].add, "\n")] = '\0';printf("Enter mobile number: ");fgets(emp[i].mobile, sizeof(emp[i].mobile), stdin);emp[i].mobile[strcspn(emp[i].mobile, "\n")] = '\0';printf("Enter gender (M/F): ");scanf(" %c", &emp[i].gender);printf("Enter salary: ");scanf("%f", &emp[i].salary);}// Display employee recordsprintf("\n========== EMPLOYEE RECORDS ==========\n");for (i = 0; i < N; i++){printf("\nDetails of Employee %d:\n", i + 1);printf("Employee ID : %d\n", emp[i].eid);printf("Name : %s\n", emp[i].ename);printf("Designation : %s\n", emp[i].des);printf("Address : %s\n", emp[i].add);printf("Mobile No. : %s\n", emp[i].mobile);printf("Gender : %c\n", emp[i].gender);printf("Salary : Rs. %.2f\n", emp[i].salary);}return 0;}
Sample Output
Enter details of Employee 1:Enter employee ID: 101Enter employee name: Rahul SharmaEnter designation: ManagerEnter address: Indore, MPEnter mobile number: 9876543210Enter gender (M/F): MEnter salary: 45000========== EMPLOYEE RECORDS ==========Details of Employee 1:Employee ID : 101Name : Rahul SharmaDesignation : ManagerAddress : Indore, MPMobile No. : 9876543210Gender : MSalary : Rs. 45000.00... Records of remaining employees ...
Note: The program accepts and displays records of all 10 employees.
Explanation
Structure Declaration:
struct employeedefines seven data members to store employee details.struct employeeमें Employee की जानकारी Store करने के लिए सात Data Members Declare किए गए हैं।Array of Structures:
struct employee emp[N];creates an array to store 10 employee records.यह Statement 10 Employees के Records Store करने के लिए Array बनाता है।
Input: The first
forloop accepts the details of all employees.पहला
forLoop सभी Employees की जानकारी Input करता है।Display: The second
forloop displays the stored employee records.दूसरा
forLoop Store किए गए सभी Employee Records को Display करता है।Member Access: The dot (
.) operator is used to access individual structure members, such asemp[i].enameandemp[i].salary.Dot (
.) Operator का उपयोग Structure के अलग-अलग Members को Access करने के लिए किया जाता है।
Important Points
#define N 10specifies the number of employees.An array of structures stores multiple employee records.
Mobile numbers are stored as character arrays because they are identifiers, not numbers for arithmetic calculations.
fgets()allows names and addresses containing spaces.
महत्वपूर्ण बिंदु:
#define N 10Employees की संख्या निर्धारित करता है।Array of Structures का उपयोग Multiple Employee Records Store करने के लिए किया जाता है।
Mobile Number को Character Array में Store किया जाता है क्योंकि इस पर Arithmetic Calculations नहीं की जाती हैं।
fgets()की सहायता से Space सहित Name और Address Input किए जा सकते हैं।
Comments
Post a Comment