It's is a Very Hard For Being.. You Want To Copy This Code
#include <stdio.h>
#include <stdlib.h>
typedef struct{
char name[30];
int id;
double salary;
} Employee;
int main()
{
//number of employees
int n=2;
//array to store structure values of all employees
Employee employees[n];
//Taking each employee detail as input
printf("Enter %d Employee Details \n \n",n);
for(int i=0; i<n; i++){
printf("Employee %d:- \n",i+1);
//Name
printf("Name: ");
scanf("%[^\n]s",employees[i].name);
//ID
printf("Id: ");
scanf("%d",&employees[i].id);
//Salary
printf("Salary: ");
scanf("%lf",&employees[i].salary);
//to consume extra '\n' input
char ch = getchar();
printf("\n");
}
//Displaying Employee details
printf("-------------- All Employees Details ---------------\n");
for(int i=0; i<n; i++){
printf("Name \t: ");
printf("%s \n",employees[i].name);
printf("Id \t: ");
printf("%d \n",employees[i].id);
printf("Salary \t: ");
printf("%.2lf \n",employees[i].salary);
printf("\n");
}
return 0;
}
The output of the Program:
C Program for Employee Details using Structure
Calculate Salary of the Employee from Basic
In the above program, we are directly asking the user to input the salary of every employee.
In case we need to calculate the salary from the basic, we will have to add an extra variable (i.e. basic_salary) to the structure and calculate the net_salary using the formula: net_salary = basic_salary + HRA + DA – PF
Where,
HRA is 10% of basic salary i.e., HRA=basic_salary0.1;
DA is 5% of basic salary i.e., DA=basic_salary0.05;
PF is 12% of basic salary i.e., PF=basic_salary*0.12;
Putting them in the formula: net_salary = basic_salary * (1+ 0.1 + 0.05 – 0.12).
If we modify the above program then the code will be:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
char name[30];
int id;
double basic_salary;
double net_salary;
} Employee;
int main()
{
//number of employees
int n=2;
//array to store structure values of all employees
Employee employees[n];
//Taking each employee detail as input
printf("Enter %d Employee Details \n \n",n);
for(int i=0; i<n; i++){
printf("Employee %d:- \n", (i+1));
//Name
printf("Name: ");
scanf("%[^\n]s",employees[i].name);
//ID
printf("Id: ");
scanf("%d",&employees[i].id);
//Salary
printf("Basic Salary: ");
scanf("%lf",&employees[i].basic_salary);
//to consume extra '\n' input
char ch = getchar();
employees[i].net_salary = employees[i].basic_salary*1.03;
}
//Displaying Employee details
printf("-------------- All Employees Details ---------------\n");
for(int i=0; i<n; i++){
printf("Name \t: ");
printf("%s \n",employees[i].name);
printf("Id \t: ");
printf("%d \n",employees[i].id);
printf("Salary \t: ");
printf("%.2lf \n",employees[i].net_salary);
printf("\n");
}
return 0;
}
If you didn’t understand any part of the code then do comment below.
You May Also Like:
C Program for Student Details using Structure
Solve Tower of Hanoi using Recursion in C
C Program to Reverse Array without Using another Array
How to Create an Array of Strings in C?
THIS POST HAS 30 COMMENTS
BalajiFEBRUARY 20, 2020 REPLY
What is the difference between array and structure array
Adarsh KumarFEBRUARY 21, 2020 REPLY
They both are similar. The difference is the type of data in the array. When we declare int array[10], we mean to store integers into the array and in case of Employee array[10], we mean to store structure objects into the array.
BalajiFEBRUARY 20, 2020 REPLY
Why you have write the Employee; after defining structure
Adarsh KumarFEBRUARY 21, 2020 REPLY
Any name you put at the end of the structure declaration along with typedef at the beginning is used to rename the structure. In our case, we have renamed the structure as Employee. so that we can address the structure in main funtion using just Employee instead of struct Employee.
Shaik AminAPRIL 9, 2020 REPLY
Write a program to read the details of ‘N’ employees (ID, Name, Salary) and display the details of those employees whose salary is above Rs.10,000/-.
Can any one write this program.?
Adarsh KumarAPRIL 10, 2020 REPLY
The logic of your problem can be easily solved using the above program. Just include if(employees[i].salary> 10000) indide the loop which prints the employee details.
for(i=0; i 10000){
printf("Name \t: ");
printf("%s \n",employees[i].name);
printf("Id \t: ");
printf("%d \n",employees[i].id);
printf("Salary \t: ");
printf("%d \n",employees[i].salary);
printf("\n");
}
}
MayureshDECEMBER 15, 2021 REPLY
create a structure employee (eno, ename, salary) Accept details of n employees and write a menu driven program to perform the following Quetions.
1.isplay all employees having salary > 5000
2.Display all employees
Can you solve this?
RekhaAPRIL 23, 2020 REPLY
- Write a Menu Driven C program to create an employee database using structure and perform following operations: (I) Accept Employee Record (II) Display All Employees Records (III) Search Employee Record by name and Display (IV) Search Employee Record by Employee ID and Display (V) Update Employee Record (Note: Employee record will have following fields Employee ID, Employee Name, Employee Department, Employee Salary)
can i pls get a code for this
Ritik vaniAPRIL 23, 2020 REPLY
How to add date of joining of the employee in the program
Adarsh KumarAPRIL 25, 2020 REPLY
Add another char array (string) to store the date of joining.
typedef struct{
char name[30];
int id;
int salary;
char dateOfJoining[20];
} Employee;
JayashreeAPRIL 24, 2020 REPLY
In case of storing 20 employees,we need to change ?
Adarsh KumarAPRIL 25, 2020 REPLY
change the value of n
n=20
Amira osamaOCTOBER 30, 2020 REPLY
if I want to print details of one employee by his id what should I do?
Adarsh KumarOCTOBER 30, 2020 REPLY
If you want to print an employee by his id use any of the search algorithms such as linear search or binary search to search an employee in the employee array. If found then output his details.
int id;
scanf("%d", &id);
for(int i=0; i<n; i++){
if(employees[i].id == id){
printf("Name \t: ");
printf("%s \n",employees[i].name);
printf("Id \t: ");
printf("%d \n",employees[i].id);
printf("Salary \t: ");
printf("%d \n",employees[i].salary);
}
}
SakshiSEPTEMBER 16, 2021 REPLY
Hi Adarsh, could you please tell me how can I compute total salary outgo for a month . For an employee using structures in C.
Thanks in advance .
Adarsh KumarSEPTEMBER 17, 2021 REPLY
Updated the post with the solution.
SakshiSEPTEMBER 17, 2021 REPLY
Thank you so much for the reply Adarsh . This has helped me .
SakshiSEPTEMBER 20, 2021 REPLY
Write a C program – using structures for reading the employee details like employee name, date of joining and salary and also to compute Total salary outgo for a month.
Could you please provide a solution for this pleasee?
SakshiSEPTEMBER 20, 2021 REPLY
The above program is giving error as ” array subscipt is not an integer” kindly suggest.
Adarsh KumarSEPTEMBER 24, 2021 REPLY
From my side, the code is working fine. Maybe you are trying to input the full name of the employee. Can you re-check, I have modified the code.
RohanSEPTEMBER 21, 2021 REPLY
Write a C program – using structures for reading the employee details like employee name, date of joining and salary and also to compute Total salary outgo for a month ??
can you please share code for the same .
Muhereza EMMANUELOCTOBER 27, 2021 REPLY
How can compute the total amont if the employees
hannahNOVEMBER 26, 2021 REPLY
how can I delete a certain employee from the list of array?
Ansh patelMAY 7, 2022 REPLY
Can do you can prepare the code on this
Create a structure to store employee’s data with the following information: Employee’s no., Employee’s name, Employee’s pay, date of joining (which is itself a structure) (i) It is decided to increase the pay as per the following rules: Pay<=Rs. underline 200 : 15 % increase Pay R . 2000: 10% increase Pay > Rs * .5000 : no increase Write a program to do this. (Assume there are 200 employees.) (ii) Write a program to print details of employees who have completed 20 years service.”
Saksham SubediDECEMBER 1, 2022 REPLY
Write a program to input emp no, name and salary of 100 employees using structure. Display the name and salary of employee using structure.
SaniaDECEMBER 9, 2022 REPLY
Plz help me write a code to find the employee whose getting highest salary…
wan aniqJANUARY 7, 2023 REPLY
how we can input the n? means n should entered by users in output
ShwetaMAY 4, 2023 REPLY
Hey adarsh can u help me with this
Prepare a menu driven program for employee record system
1.Add record
2.List record
shashankJUNE 30, 2023 REPLY
how can you delete a record?
aboyzsJULY 3, 2023 REPLY
Hello, please help on how to create an employee structure to store five employee records in a linked list. The employee structure is given as:
struct employee {
int id;
char name[25];
float salary;
} records [5];
Thanks..
Leave a Reply
Comment
Your comment here...
Enter your name or username to comment
Name (required)
Enter your email address to comment
Email (required)
Enter your website URL (optional)
Website
Save my name, email, and website in this browser for the next time I comment.Alternative:
Alternative:
Search
Search
SEARCH