C Programming
Computer Programming

C Program using structure to Display details of highest paid employee



Write a C program to accept details of 'n' employee(eno, ename, salary) and display the details of employee having highest salary. Use array of structure

\* C Program using structure to Display details of highest paid employee *\

# include < stdio.h >
# include < conio.h >
struct   employee
{

int eno ;
char ename[20] ;
int salary ;

} emp[10] ;

int   main( )
{

int i, high, n ;
printf("\n /*How many employee info you want to accept ! ") ;
printf("\n Enter Limit: ") ;
scanf("%d", &n ) ;
printf(" -----------------------------\n" ) ;
printf(" Enter details for %d employees:", n ) ;
printf("\n -----------------------------\n" ) ;
for( i = 0 ; i < n ; i++ )
{
      printf(" Enter %d employees details !", i+1 ) ;
      printf("\n Employee Number: ") ;
      scanf("%d",&emp[i].eno) ;
      printf(" Name : ") ;
      scanf("%s",emp[i].ename) ;
      printf(" Salary : ") ;
      scanf("\n %d",&emp[i].salary) ;
      printf(" -----------------------------\n") ;
}
high = emp[0].salary ;
for(i = 0 ; i < n ; i++ )
{
      if(emp[i].salary>high)
            high = emp[i].salary ;
}
printf(" Highest salary employee details:") ;
printf("\n -----------------------------\n") ;
printf(" EMPNO NAME SALARY\n") ;
for( i = 0; i < n; i++ )
{
      if(emp[i].salary == high)
            printf("\n %d\t%s\t%d", emp[i].eno, emp[i].ename, emp[i].salary) ;
}
return 0;

}

Output of Program :

Output of C Program using structure to Display details of highest paid employee