C Program to store the records of n Employees (ID , Names , Department , Salaries) and display the records of those who are working in a given department and have a saary more than 50000.

 


// Program by Akash Tripathi (@proakash256) 
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
struct employee
{
    char ID[13];
    char Name[1024];
    char Department[11];
    int Salary;
};
typedef struct employee employee;
int main()
{
    int n;
    printf("Enter the number of Employees : ");
    scanf("%d", &n);
    employee *em = malloc(n * (sizeof(employee)));
    for (int i = 0i < ni = i + 1)
    {
        printf("\nEnter the details of Employee %d :\n"i);
        printf("ID : ");
        scanf("%s"em[i].ID);
        getchar();
        printf("Name : ");
        gets(em[i].Name);
        getchar();
        printf("Department : ");
        scanf("%s"em[i].Department);
        getchar();
        printf("Salary : ");
        scanf("%d", &em[i].Salary);
        getchar();
    }
    printf("\nEnter the Department : ");
    char d[11];
    scanf("%s"d);
    printf("Employees in the %s Department with salary 
greater than 50000 are :\n\n");
    for (int i = 0i < ni = i + 1)
    {
        if (strcmp(em[i].Departmentd) == 0)
        {
            if (em[i].Salary > 50000)
            {
                printf("ID : %s\n" , em[i].ID);
                printf("Name : %s\n"em[i].Name);
                printf("Department : %s\n"em[i].Department);
                printf("Salary : %d\n\n"em[i].Salary);
            }
        }
    }
    return 0;
}

Comments