Monday, July 31, 2017

Find highest paid employee in C

#include<stdio.h>
struct emp
{
    char name[50];
    int salary;
};
void main()
{
    int n,i,sum=0,avg;
    struct emp e[20],ls,hs;
    printf("Enter the number of employee : ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter the name and salary of employees : ");
        scanf("%s%d",e[i].name,&e[i].salary);
        sum = sum + e[i].salary;
    }
    avg = sum/n;
    ls.salary=e[0].salary;
    for(i=1;i<n;i++)
    {
        if(ls.salary>e[i].salary)
        {
            ls=e[i];
        }
    }
    hs.salary=e[0].salary;
    for(i=1;i<n;i++)
    {
        if(hs.salary<e[i].salary)
        {
            hs=e[i];
        }
    }
    printf("\nAVERAGE SALARY = %d",avg);
    printf("\n\nThe highest salary of employee is\nNAME\t\tSALARY");
    printf("\n%s\t\t%d",hs.name,hs.salary);
    printf("\n\nThe lowest salary of employee is\nNAME\t\tSALARY");
    printf("\n%s\t\t%d",ls.name,ls.salary);
    printf("\n\nEMPLOYEE HAVING SALARY ABOVE 15000");
    printf("\nNAME\t\tSALARY");
    for(i=0;i<n;i++)
    {
        if(e[i].salary>15000)
        {
            printf("\n%s\t\t%d",e[i].name,e[i].salary);
        }
    }
    getch();
}

Related Posts:

  • Code in C to multiply two matrix#include<stdio.h> void matmultiply(int m[3][3], int n[3][3]); void read(int x[3][3]); //void read2(int y[3][3]); void main() {     int a[3][3],b[3][3],l,w;     printf("\nFor matrix a :-\n");   &… Read More
  • Copying string 2 to string 1#include<stdio.h> void copystr(char [],char []); void main() {     char str1[50],str2[50];     printf("Enter 1st string,str1 : ");     gets(str1);     printf("\nEnter 2nd string,s… Read More
  • Telephone directory Code for telephone directory in c #include<stdio.h> #include<string.h> #include<windows.h> #include<time.h> struct teledir {     char firstname[50];     char lastname[50… Read More
  • Sorting names in C#include<stdio.h> //#include<string.h> void copystring(char txt1[], char txt2[]) {     int k;     for(k=0;txt2[k]!='\0';k++)     {         txt1[k]=txt2[k];  … Read More
  • Concatenation of two string in C#include<stdio.h> void catstr(char [],char []); void main() {     char str1[50],str2[50];     printf("Enter 1st string (str1) :");     gets(str1);     printf("\nEnter 2nd string (… Read More

0 comments:

Post a Comment