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 10
struct 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 records
for (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 records
printf("\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: 101
Enter employee name: Rahul Sharma
Enter designation: Manager
Enter address: Indore, MP
Enter mobile number: 9876543210
Enter gender (M/F): M
Enter salary: 45000

========== EMPLOYEE RECORDS ==========
Details of Employee 1:
Employee ID : 101
Name : Rahul Sharma
Designation : Manager
Address : Indore, MP
Mobile No. : 9876543210
Gender : M
Salary : Rs. 45000.00
... Records of remaining employees ...

Note: The program accepts and displays records of all 10 employees.

Explanation

  1. Structure Declaration: struct employee defines seven data members to store employee details.

    struct employee में Employee की जानकारी Store करने के लिए सात Data Members Declare किए गए हैं।

  2. Array of Structures: struct employee emp[N]; creates an array to store 10 employee records.

    यह Statement 10 Employees के Records Store करने के लिए Array बनाता है।

  3. Input: The first for loop accepts the details of all employees.

    पहला for Loop सभी Employees की जानकारी Input करता है।

  4. Display: The second for loop displays the stored employee records.

    दूसरा for Loop Store किए गए सभी Employee Records को Display करता है।

  5. Member Access: The dot (.) operator is used to access individual structure members, such as emp[i].ename and emp[i].salary.

    Dot (.) Operator का उपयोग Structure के अलग-अलग Members को Access करने के लिए किया जाता है।

Important Points

  • #define N 10 specifies 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 10 Employees की संख्या निर्धारित करता है।

  • Array of Structures का उपयोग Multiple Employee Records Store करने के लिए किया जाता है।

  • Mobile Number को Character Array में Store किया जाता है क्योंकि इस पर Arithmetic Calculations नहीं की जाती हैं।

  • fgets() की सहायता से Space सहित Name और Address Input किए जा सकते हैं।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025