-
-
Save wise-introvert/b2145043bb2b870e26bb91aacfd1ca18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct employee { | |
int empId; | |
float salary; | |
}; | |
int main(void) { | |
int i; | |
float total_salary = 0.0; | |
//declare an employee type ARRAY variable of size 3 named: emp(3 mark) | |
struct employee emp[3]; | |
printf("\nEnter details for 3 employees:\n"); | |
//iterating the loop until the size of the array (2 marks) | |
for (i = 0; i < 3; i++) { | |
printf("\nEnter ID : "); | |
// Store user input value for employee id to the appropriate emp | |
//Employee member element (1 mark) | |
scanf("%d", & emp[i].empId); | |
printf("Enter salary : "); | |
// Store user input value for employee salary to the appropriate emp | |
// Employee member element (1 mark) | |
scanf("%f", & emp[i].salary); | |
} | |
printf("\nEntered details are :\n"); | |
//iterating the loop until the size of the array (2 marks) | |
for (i = 0; i < 3; i++) { | |
//printing all the structure member values (3 marks) | |
printf("\nId:%d\t Salary:%.2f\t", emp[i].empId, emp[i].salary); | |
} | |
//iterating the loop until the size of the array (2 marks) | |
for (i = 0; i < 3; i++) { | |
// Calculate the total salary of all the employees (2 mark) | |
total_salary += emp[i].salary; | |
} | |
// Print total salary of all the employees (2 marks) | |
printf("\nTotal salary = %.2f", total_salary); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment