DS STRUCTURE
Your code demonstrates the use of a structure in C to store
and manage employee details like ID, salary, and mobile number. However, there
are a few issues in the code that need correction. Here’s the corrected
version:
Corrected Program
#include<stdio.h>
#include<conio.h>
{
struct
employee
{
int id;
float
salary;
int
mobile;
};
struct employee
e1, e2, e3;
clrscr();
printf("\nEnter ids, salary & mobile no. of 3
employees\n");
scanf("%d %f
%d", &e1.id, &e1.salary, &e1.mobile);
scanf("%d %f
%d", &e2.id, &e2.salary, &e2.mobile);
scanf("%d %f
%d", &e3.id, &e3.salary, &e3.mobile);
printf("\nEntered Result:\n");
printf("\n%d
%.2f %d", e1.id, e1.salary, e1.mobile);
printf("\n%d
%.2f %d", e2.id, e2.salary, e2.mobile);
printf("\n%d
%.2f %d", e3.id, e3.salary, e3.mobile);
getch();
}
Corrections Made:
- Missing Parenthesis: Added the closing parenthesis in the `printf` function call.
- Formatting the Output: In the `printf` statements for displaying salary, I used `%.2f` to format the salary as a floating-point number with two decimal places for clarity.
- Additional Spaces: Added spaces in the output to ensure consistent formatting, especially between values.
Explanation:
- Memory Management: The structure helps in grouping related data together, making it easier to manage and access using a single identifier (like `e1`, `e2`, or `e3`).
- Functionality: The program prompts the user to input the details of three employees, stores them in the structure variables, and then prints out the entered details.