Program to perform menu driven structure operations on structure employee


C File =>

/* Write a C program to create structure employee (id, name, salary). Accept details of n employees and perform the following operations:
a. Display all employees.
b. Display details of all employees having salary > 15000. */


#include<stdio.h>
#include<stdlib.h>


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


int main()
{
    struct employee e[10];
    int n,i,ch;
    printf("\n How many employees? ");
    scanf("%d",&n);
   for(i=0;i<n;i++)
  {
          printf("\n\n Enter employee id%d : ",i+1);
          scanf("%d",&e[i].id);
          printf("\n Enter name%d : ",i+1);
          scanf("%s",e[i].name);
          printf("\n Enter Salary%d : ",i+1);
          scanf("%f",e[i].salary);
    }
      printf("\n 1. Display details of all\n 2.Display employee having salary>15000");
      printf("\n 3. Exit \n Select operation : ");
      scanf("%d",&ch);
      do
      {
          switch(ch)
         {
            case 1: for(i=0;i<n;i++)
                        {
                            printf("\n\n Employee ID : %d",e[i].id);
                            printf("\n Name : %s",e[i].name);
                            printf("\n Salary : %f",e[i].salary);
                         }
            break;
            case 2: for(i=0;i<n;i++)
                        {
                            if(e[i].salary>15000)
                           {
                              printf("\n\n Employee ID : %d\n" ,e[i].id);
                              printf("Name : %s\n Salary : %f",e[i].name,e[i].salary);
                            }
                         }
             break;
             case 3: exit(0);
             break;
             default : printf("\n Invalid input");
           }
       }while(ch!=3);
return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.