Q:

C program to read and print an employee\'s detail using structure

belongs to collection: C Structure and Union programs

0

C program to read and print an employee's detail using structure

C program to read and print an Employee’s Details using Structure - In this program, we will read employee’s details like name, employee id and salary using structure and then print the entered values.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Employee Detail program in C

/*C program to read and print employee's record using structure*/
 
#include <stdio.h>
 
/*structure declaration*/
struct employee{
    char    name[30];
    int     empId;
    float   salary;
};
 
int main()
{
    /*declare structure variable*/
    struct employee emp;
     
    /*read employee details*/
    printf("\nEnter details :\n");
    printf("Name ?:");          gets(emp.name);
    printf("ID ?:");            scanf("%d",&emp.empId);
    printf("Salary ?:");        scanf("%f",&emp.salary);
     
    /*print employee details*/
    printf("\nEntered detail is:");
    printf("Name: %s"   ,emp.name);
    printf("Id: %d"     ,emp.empId);
    printf("Salary: %f\n",emp.salary);
    return 0;
}

Output

Enter details :
Name ?:Mike
ID ?:1120
Salary ?:76543

Entered detail is:
Name: Mike
Id: 1120
Salary: 76543.000000

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to demonstrate example of Nested Structu... >>
<< C program to create, declare and initialize struct...