Reading name, post and salary of 10 different employees and displaying those records whose salary is greater than 10000 using user defined function

Question: Write a program in C to input name, post and salary of 10 employees from main() function and pass to a user defined function (argument of this function should also be structure type). This function return structure variable which keeps the record of only those employees whose salary is greater than 10,000. This modified record is displayed from main() function.

Program


#include<stdio.h>
#include<conio.h>

typedef struct
{
 char name[30];
 char post[30];
 int salary;
}employee;

int salarySelect(employee e[10], employee r[10]);

int main()
{
 employee e[10], r[10];
 int i, n;
 clrscr();
 /* Taking Input */
 for(i=0;i< 10;i++)
 {
  printf("Enter name, post and salary of employees:\n");
  scanf("%s%s%d", e[i].name, e[i].post, &e[i].salary);
 }
 /* Passing to Function
    Here structure array r[10] is empty in which we will store
    those record of employee whose salary is above 10000 in user
    defined function and later we will print from main() function
 */
 /* Value returned by function salarySelect() indicates there are
    n employee records whose salary is greater than 10000
 */
 n = salarySelect(e,r);
 /* Displaying Result */
 printf("All employee records whose salary above 10000 are:\n");
 for(i=0;i< n;i++)
 {
  printf("Name = %s\n", r[i].name);
  printf("Post = %s\n", r[i].post);
  printf("Salary = %d\n", r[i].salary);
 }
 getch();
 return 0;
}
/* Function Definition */
int salarySelect(employee e[10], employee r[10])
{
 int i,j=0;
 for(i=0;i< 10;i++)
 {
  if(e[i].salary>10000)
  {
   r[j] = e[i];
   j++;
  }
 }
 /* We are returning value of j because this information is
    required in main() function while displaying records
 */
 return j;
}