Computer Science, asked by tejinmavoor, 5 hours ago

Declare a student structure with the following details. Employee name, Emp Id, Basic Salary, DA and HRA and Total Salary. Write a C program to read the Employee name, Emp Id, Basic Salary, DA and HRA of an employee from the user and then calculate and update Total Salary​

Answers

Answered by rushikeshg86
0

Answer:

#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;

}

Explanation:

Similar questions