Last active
April 19, 2022 06:27
-
-
Save bikashthapa01/1a7080646b3d8e8ba409cee3a9de6fd5 to your computer and use it in GitHub Desktop.
Lab Works 2 Programs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lab Works 2 : Program no 3 | |
#include <stdio.h> | |
void sorting(int n); | |
struct student { | |
int sid; | |
char name[20]; | |
int height; | |
} s[100]; | |
int main(){ | |
int n,i; | |
printf("Enter Number of Records to save \n"); | |
scanf("%d",&n); | |
for(i=0;i<n;i++){ | |
printf("Enter student id:\n"); | |
scanf("%d",&s[i].sid); | |
printf("Enter student Name:\n"); | |
scanf("%s",s[i].name); | |
printf("Enter student Height:\n"); | |
scanf("%d",&s[i].height); | |
} | |
sorting(n); | |
} | |
void sorting(int n){ | |
struct student temp; | |
int i,j; | |
for(i=0;i<n-1;i++){ | |
for(j=i+1;j<n;j++){ | |
if(s[i].height > s[j].height){ // greater than sorts item in Ascending order // less than sorts item in descending order | |
temp = s[i]; | |
s[i] =s[j]; | |
s[j] = temp; | |
} | |
} | |
} | |
for(i=0;i<n;i++){ | |
printf("\n=========== Student Record - %d ===========\n",i+1); | |
printf("student id: %d\n",s[i].sid); | |
printf("student Name: %s\n",s[i].name); | |
printf("student Height: %d\n",s[i].height); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lab Works 2 : Program no 4 | |
#include <stdio.h> | |
void search(int eid, int n); | |
struct employee { | |
int empid; | |
char name[20]; | |
int salary; | |
} e[100]; | |
int main(){ | |
int n,i,eid; | |
printf("Enter Number of Records to save \n"); | |
scanf("%d",&n); | |
for(i=0;i<n;i++){ | |
printf("Enter Employee id:\n"); | |
scanf("%d",&e[i].empid); | |
printf("Enter Employee Name:\n"); | |
scanf("%s",e[i].name); | |
printf("Enter Employee Salary:\n"); | |
scanf("%d",&e[i].salary); | |
} | |
printf("Enter Employee Id to Search :\n"); | |
scanf("%d",&eid); | |
search(eid,n); | |
} | |
void search(int eid,int n){ | |
int found = 0; | |
int i; | |
for(i=0;i<n;i++){ | |
if(e[i].empid == eid){ // checking if given employee id is present in database or not | |
found= 1; | |
break; | |
} | |
} | |
if(found){ | |
printf("\n=========== Employee Found in %dth Position ===========\n",i+1); | |
printf("Employee id: %d\n",e[i].empid); | |
printf("Employee Name: %s\n",e[i].name); | |
printf("Employee Salary: %d\n",e[i].salary); | |
}else{ | |
printf("No Record Found!"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lab Works 2 : Program no 4 | |
#include <stdio.h> | |
void findMax(int n); | |
struct employee { | |
int empid; | |
char name[20]; | |
char post[20]; | |
int salary; | |
} e[100]; | |
int main(){ | |
int n,i; | |
printf("Enter Number of Records to save \n"); | |
scanf("%d",&n); | |
for(i=0;i<n;i++){ | |
printf("Enter Employee id:\n"); | |
scanf("%d",&e[i].empid); | |
printf("Enter Employee Name:\n"); | |
scanf("%s",e[i].name); | |
printf("Enter Employee Post:\n"); | |
scanf("%s",e[i].post); | |
printf("Enter Employee Salary:\n"); | |
scanf("%d",&e[i].salary); | |
} | |
findMax(n); | |
} | |
void findMax(int n){ | |
int max = e[0].salary; | |
int i,position=0; | |
for(i=0;i<n;i++){ | |
if(max<e[i].salary){ | |
max = e[i].salary; | |
position=i; | |
} | |
} | |
printf("\n=========== Employee Found in %dth Position ===========\n",position+1); | |
printf("Employee id: %d\n",e[position].empid); | |
printf("Employee Name: %s\n",e[position].name); | |
printf("Employee Post: %s\n",e[position].post); | |
printf("Employee Salary: %d\n",e[position].salary); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment