Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<malloc.h>
- #include<string.h>
- struct emp
- {
- char name[10];
- char designation[10];
- float salary;
- struct emp *ptr;
- };
- struct emp * addelement(struct emp *,char name[],char des[],float );
- void display(struct emp *);
- void average(struct emp *);
- int main()
- {
- int num,i;
- struct emp *head;
- float sal;
- head=NULL;
- char name[10],des[10];
- printf("\n Enter the number of employees to be added to the database :");
- scanf("%d",&num);
- for(i=1;i<=num;i++)
- {
- printf("Enter the name of the employee :");
- scanf("%s",name);
- printf("\n Enter the designation of the employee :");
- scanf("%s",des);
- printf("\n Enter the salary of the employee : ");
- scanf("%f",&sal);
- head=addelement(head,name,des,sal);
- }
- printf("\n The employee information is as follows ");
- display(head);
- average(head);
- }
- struct emp * addelement(struct emp *head,char name[10],char des[10],float sal)
- {
- struct emp *newnode;
- newnode=(struct emp *)malloc(sizeof(struct emp));
- strcpy(newnode->name,name);
- strcpy(newnode->designation,des);
- newnode->salary=sal;
- if(head==NULL)
- {
- newnode->ptr=NULL;
- return newnode;
- }
- else
- {
- newnode->ptr=head;
- return newnode;
- }
- }
- void display(struct emp *p3)
- {
- if(p3==NULL)
- {
- printf("\n The list is empty \n");
- }
- while(p3!=NULL)
- {
- printf("\n Employee Name: %s,Employee Designation: %s,salary: %f",p3->name,p3->designation,p3->salary);
- p3=p3->ptr;
- }
- }
- void average(struct emp *p4)
- {
- float average,sal=0;
- int n=0;
- if(p4==NULL)
- {
- printf("\n The List is empty");
- }
- while(p4!=NULL)
- {
- if((strcmp(p4->designation,"manager")==0)||(strcmp(p4->designation,"MANAGER")==0))
- {
- sal=sal+(p4->salary);
- n++;
- }
- p4=p4->ptr;
- }
- average=(sal)/n;
- printf("\n The Average salary of manager in the organisation : %f",average);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement