0% found this document useful (0 votes)
6 views2 pages

Week 4

The document contains a C program that defines a structure for employee data, including employee number, name, and salary. It prompts the user to input details for multiple employees and sorts them based on their salary in descending order. Finally, it displays the sorted list of employees.

Uploaded by

karthikpro56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Week 4

The document contains a C program that defines a structure for employee data, including employee number, name, and salary. It prompts the user to input details for multiple employees and sorts them based on their salary in descending order. Finally, it displays the sorted list of employees.

Uploaded by

karthikpro56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Week #4 - Structures

#include<stdio.h>

struct employee

int empno;

char empname[20];

float salary;

};

void main()

struct employee e[20],temp;

int i,j,n;

printf("\nEnter no. of Employees : ");

scanf("%d",&n);

for(i=0;i<n;i++)

printf("\n Enter the Employee Number: ");

scanf("%d",&e[i].empno);

printf("\n Enter the Employee Name: ");

scanf("%s",&e[i].empname);

printf("\n Enter the Employee Salary: ");

scanf("%f",&e[i].salary);

for(i=0;i<=n-1;i++)

for(j=0;j<=n-1;j++)

if(e[j].salary<e[j+1].salary)
{

temp=e[j];

e[j]=e[j+1];

e[j+1]=temp;

printf("\nThe Employee Sorted List bassed on salary\n");

printf("\n*******************************************\n");

printf("\nEmp.No\tEmp.Name\tSalary\n");

for(j=0;j<n;j++)

printf("%d\t%s\t%f\n",e[j].empno,e[j].empname,e[j].salary);

getch();

You might also like