DS STRUCTURE

Deepa

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> 

 void main() 

{ 

    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:

  1. Missing Parenthesis: Added the closing parenthesis in the `printf` function call.
  2. 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.
  3. Additional Spaces: Added spaces in the output to ensure consistent formatting, especially between values.

 

Explanation:

  1.  Structures: This code defines a structure `employee` that contains three variables: `id`, `salary`, and `mobile`. Each `struct employee` instance holds these three data points for a single employee.
  2. 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`).
  3. 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.

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send