Knowee
Questions
Features
Study Tools

Write a C program to store the information of employees in a company using structures. Each employee should have the following details:Employee code (integer)Employee name (string)Salary (float)Department number (integer)The program should allow the user to input the number of employees (n) and then input the details of each employee. i.Display the employee name with the maximum salary.ii. Display the average salary of all employees in the company.Test Case:3 // number of employees101  //Enter employee code:John Doe // Enter employee name:50000.00 // Enter salary:1  // Enter department number:102Jane Smith60000.001103Suresh Raina55000.002Output:Jane Smith55000.00  // avg of all employees salary

Question

Write a C program to store the information of employees in a company using structures. Each employee should have the following details:Employee code (integer)Employee name (string)Salary (float)Department number (integer)The program should allow the user to input the number of employees (n) and then input the details of each employee. i.Display the employee name with the maximum salary.ii. Display the average salary of all employees in the company.Test Case:3 // number of employees101  //Enter employee code:John Doe // Enter employee name:50000.00 // Enter salary:1  // Enter department number:102Jane Smith60000.001103Suresh Raina55000.002Output:Jane Smith55000.00  // avg of all employees salary

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C program that fulfills your requirements:

#include <stdio.h>
#include <string.h>

struct Employee {
    int code;
    char name[50];
    float salary;
    int dept;
};

int main() {
    int n, i, maxIndex = 0;
    float totalSalary = 0.0, avgSalary;
    printf("Enter the number of employees: ");
    scanf("%d", &n);
    struct Employee emp[n];

    for(i = 0; i < n; i++) {
        printf("Enter employee code: ");
        scanf("%d", &emp[i].code);
        printf("Enter employee name: ");
        scanf("%s", emp[i].name);
        printf("Enter salary: ");
        scanf("%f", &emp[i].salary);
        printf("Enter department number: ");
        scanf("%d", &emp[i].dept);

        totalSalary += emp[i].salary;

        if(emp[i].salary > emp[maxIndex].salary) {
            maxIndex = i;
        }
    }

    avgSalary = totalSalary / n;

    printf("Employee with maximum salary: %s\n", emp[maxIndex].name);
    printf("Average salary of all employees: %.2f\n", avgSalary);

    return 0;
}

This program first asks for the number of employees. Then it creates an array of Employee structures of that size. It then enters a loop where it asks for the details of each employee and stores them in the structure. It also keeps track of the total salary and the index of the employee with the maximum salary. After the loop, it calculates the average salary and prints the name of the employee with the maximum salary and the average salary.

This problem has been solved

Similar Questions

Design a structure in C to represent an employee's information, including their name, employee ID, department, and salary. Additionally, write a program that allows users to input employee data, display employee information, and update an employee's salary. write a code for demonstrating the implementation of the structure and program functionalities.input and output Enter employee details:Enter employee name: John DoeEnter employee ID: 101Enter department: SalesEnter salary: 50000Employee Information:Name: John Employee ID: 101 Department:Sales Salary: 50000.00Enter new salary: 55000Salary updated successfully.Updated Employee Information:Name: JohnEmployee ID: 101Department: SalesSalary: 55000.00

Problem StatementIn a corporate office, HR wants to implement a program to input an employee's ID and salary. Your task is to assist him in using pointers to efficiently manage and print the employee details, displaying the ID and salary for accurate record-keeping.Input format :The first line of input consists of an integer, representing the employee ID.The second line consists of a float value, representing the salary of the employee.Output format :The first line of output prints "ID: " followed by the employee ID, as an integer.The second line prints "Salary: " followed by the salary of the employee, as a float value, rounded off to two decimal places.

Consider a scenario where you need to manage records of employees in a company. Create aprogram in C that utilizes structures to handle employee information. The program shouldperform the following tasks:a. Define a structure named Employee with the following attributes:Employee ID (integer)Employee Name (string)Department (string)Salary (float)b. Create an array of structures to store information for a maximum of 5 employees.c. Display the information of the employees.

Write a C++ program to implement a class called Employee that has member variables for name, ID, appraisal_score A (out of 10) and salary. Include member functions to calculate salary based on employee performance. Create object and call the member function and print the results.If A>5 and A<8  - increment is 60% of his old salaryIf A>=8   - increment is 80% of his old salaryIf A>= 2 & A<=5-  increment is 40 % of his old salaryIf A=1 -No incrementnew salary=increment+old_salarySample InputJeny223300006Sample OutputJeny increment is 18000Jeny new salary is 48000

#include<stdio.h> struct employee{ char *empname; int salary;};int main(){ struct employee e, e1; e.empname = "Sridhar"; e1 = e; printf("%s %s", e.empname, e1.empname); return 0;}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.