C : Program to accept employee deatails and print accepted details (use structure)

--

Program :

//c program to accept employee deatails and print accepted details (use structure)
// accept employee id, name, salary

#include<stdio.h>

struct employees
{
int empid;
char empname[50];
float salary;
};

int main()
{
struct employees emp[3];

//Accepting details from user
printf("Enter detils for Employee :\n");
for(int i=1; i<=3; i++) {
printf("\nEnter details for employee %d :\n", i);

printf("Enter employee ID :");
scanf("%d", &emp[i].empid);


printf("Enter employee name :");
scanf("%s", &emp[i].empname);

printf("Enter salary per annum :");
scanf("%f", &emp[i].salary);
}

//Printing accepted details
printf("\nEmployee details :\n");
for(int i=1; i<=3; i++)
{
printf("\nEmployee %d :\n", i);

printf("Employee ID: %d\n", emp[i].empid);

printf("Employee name : %s\n", emp[i].empname);

printf("Salary per annum : %.2f\n", emp[i].salary);
}

return 0;
}

Output :

--

--

Programmer Portfolio

Code enthusiast. Learning, practicing, and sharing my journey through various programming languages, one code at a time. 🚀💻