You are on page 1of 5

NAME : SHARAN R B

REG. NO: 20MID0209


CSI2002 - DATA STRUCTURES AND ALGORITHM
ANALYSIS.

1. Accept height of n students and do the following.


1a. Arrange in descending order.
1b. Display the heights in 3X3 matrix format.

CODE:
#include <stdio.h>
void main ()
{ int height[9]; int i, j, a, x; int n = 9;
printf("Enter the students height \n");
for (i = 0; i < n; ++i)
scanf("%d", &height[i]); for (i = 0;
i< n; ++i)
{ for (j = i + 1; j < n; ++j)
{ if (height[i] <
height[j])
{
a = height[i];
height[i] = height[j];
height[j] = a;
}
} } printf(" Printing in descending order
\n"); for (i = 0; i <9; ++i)
{ printf("%d\t",
height[i]);
} printf(" \n\nPrinting in 3 X 3
\n"); x = 0; for (i = 0; i < 3; ++i)
{ for (j = 0; j < 3;
++j) {
printf("%d\t",
height[x]); x=x+1;
}
printf("\n");
}
}
OUTPUT:
Enter the students height :

45
55
65
75
95
130
150
160
170
Printing in descending order
170 160 150 130 95 75 65 55 45

Printing in 3 X 3
170 160 150
130 95 75
65 55 45

2. Define a structure with employee details such as Empid,


EmpDoJ, name and salary. Accept values for n employees,
pass structure to a function called disp () and display details
of employees whose salary is above 5000.

CODE:
#include<stdio.h>
struct org
{
char emp_name[30];
int emp_id, salary;
char emp_doj[8];
}; void
main() {
struct org employee[20];
int n,i;
void disp()
{
printf("\nEmployees Information\n");
for(i=0;i<n;i++)
{
if(employee[i].salary >= 5000)
{
printf("\nPerson %d\n Name :
%s",i+1,employee[i].emp_name);
printf("\nEmployee Id : %d",employee[i].emp_id);
printf("\nEmployee DOJ : %s",employee[i].emp_doj);
printf("\nEmployee Salary : %d",employee[i].salary);
}
}
}
printf("\nEnter the number of Employees in your organization
:");
scanf("%d", &n);
for(i = 0; i < n; i++)
{ printf("\nEnter Person %d\n Name
:",i+1);
scanf("%s",&employee[i].emp_name);
printf("\nEmployee Id :");
scanf("%d",&employee[i].emp_id); printf("\nEmployee
Date of Joining :");
scanf("%s",&employee[i].emp_doj);
printf("\nEmployee Salary :");
scanf("%d",&employee[i].salary);
} disp();
}

OUTPUT:

Enter the number of Employees in your organization :3

Enter Person 1
Name: Sharan

Employee Id: 30987

Employee Date of Joining:19/7/2013


Employee Salary:10000

Enter Person 2
Name : mukesh

Employee Id : 30988

Employee Date of Joining :19/6/2017

Employee Salary : 3000

Enter Person 3
Name : keerthi

Employee Id :40097

Employee Date of Joining :21/6/2020

Employee Salary :2000

Employees Information

Person 1
Name : Sharan
Employee Id : 30987
Employee DOJ : 19/7/2013
Employee Salary : 10000
Person 2
Name : mukesh
Employee Id : 30988
Employee DOJ : 19/6/2017
Employee Salary : 3000

You might also like