0% found this document useful (0 votes)
25 views5 pages

Experiment 8

The document describes a C program that implements functions to create, display, search, and sort a student database stored as a struct. The program uses a menu driven interface to call the different functions and allows the user to create a database, display it, search by roll number, and sort by roll number.

Uploaded by

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

Experiment 8

The document describes a C program that implements functions to create, display, search, and sort a student database stored as a struct. The program uses a menu driven interface to call the different functions and allows the user to create a database, display it, search by roll number, and sort by roll number.

Uploaded by

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

EXPERIMENT 8

NAME : SHRIRAM BHOGALE


ROLL NO : SYETA016
TITLE : STUDENT DATABASE

CODE:-
#include <stdio.h>
#include <stdlib.h>

typedef struct student


{
char name[50];
int rollNo;
float marks;
} student;

void create(student stu[], int n)


{
for (int i = 0; i < n; i++)
{
printf("\nEnter the student-%d name\n", i + 1);
scanf("%s", &stu[i].name);
printf("Enter the student-%d roll no\n", i + 1);
scanf("%d", &stu[i].rollNo);
printf("Enter the student-%d marks\n", i + 1);
scanf("%f", &stu[i].marks);
}
}
void display(student stu[], int n)
{
printf(" Name\t Roll No\t Marks \n\n");

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


{
printf("\n %s \t %d \t %f \n", stu[i].name, stu[i].rollNo,
stu[i].marks);
}
}

int search(student stu[], int n, int r)


{
for (int i = 0; i < n; i++)
{
if (stu[i].rollNo == r)
{
printf("Name : %s\n", stu[i].name);
printf("Marks : %f\n\n", stu[i].marks);
return 1;
}
}
printf("Entered RollNo not found\n");
return 0;
}

void sort(student stu[], int n)


{
struct student temp;

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


{
for (int j = i + 1; j < n; j++)
{
if (stu[i].rollNo > stu[j].rollNo)
{
temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
}

int main()
{
int ch;

int n;
int r;
struct student stu[50];

while (1)
{
printf("\nEnter the
choice:\n1)create\n2)display\n3)search\n4)sort\n5)exit\n");
scanf("%d", &ch);

switch (ch)
{
case 1:
printf("create\n\n");
printf("Enter no of students: ");
scanf("%d", &n);
create(stu, n);
break;
case 2:
printf("display\n\n");
display(stu, n);
break;
case 3:
printf("search\n\n");
printf("Enter the roll no to be searched: ");
scanf("%d", &r);
search(stu, n, r);
break;
case 4:
printf("sort\n\n");
sort(stu, n);
display(stu, n);
break;
case 5:
printf("exit\n\n");

return 0;
break;
}
}
return 0;
}
OUTPUT:-
1) Create:
2) Display:

3) Search:

4) Sort:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy