Create a structure “Employee” having Name, Address, Salary, and Age as member functions. Display the name of the employee having aged between 40 and 50 are living in Kathmandu.

This answer is restricted. Please login to view the answer of this question.

Login Now
#include <stdio.h>
#include <string.h>

struct Employee{
    char Name[100];
    char Address[500];
    int Salary;
    int Age;
};

int main(){

    int size, i, compare = 0;
    printf("Enter number of Employee: ");
    scanf("%d", &size);

    struct Employee emp[size];

    printf("\nEnter Employee Details:\n");
    for(i=0; i < size; i++){
        printf("\n\nEnter %d employee record:\n", i);
        printf("Enter Name: ");
        scanf(" %s", emp[i].Name);

        printf("Enter Address: ");
        scanf(" %s", emp[i].Address);

        printf("Enter Age: ");
        scanf(" %d", &emp[i].Age);

        printf("Enter Salary: ");
        scanf(" %d", &emp[i].Salary);
    }

    /** Print Employee with condition*/
    printf("\n\nAll the employee of Kathmandu between age 40 and 50 are: \n");
    for( i = 0; i < size; i++ ){
        compare = strcmp(emp[i].Address, "Kathmandu");
        if( compare == 0 ){
            if( emp[i].Age >= 40 && emp[i].Age <= 50 ){
                printf("%s\n", emp[i].Name);
            }
        }
    }

    return 0;
}

The output of the above program is

Enter number of Employee: 4

Enter Employee Details:


Enter 0 employee record:
Enter Name: Suresh 
Enter Address: Kathmandu
Enter Age: 45
Enter Salary: 450


Enter 1 employee record:
Enter Name: Julian
Enter Address: Dang
Enter Age: 46
Enter Salary: 230


Enter 2 employee record:
Enter Name: Lalit 
Enter Address: Kathmandu
Enter Age: 56
Enter Salary: 560


Enter 3 employee record:
Enter Name: Rajesh
Enter Address: Nepal
Enter Age: 34
Enter Salary: 120

All the employee of Kathmandu between age 40 and 50 are: 
Suresh
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .