0% found this document useful (0 votes)
1 views6 pages

Program 27

The document provides a C program that defines a student structure and implements various operations such as displaying student details, computing results, searching by roll number, and finding students with maximum and minimum marks. It utilizes functions for each operation and dynamically allocates memory for storing student data. The program allows interaction through a menu-driven interface for user input and displays the results accordingly.

Uploaded by

jhapushpam.work
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)
1 views6 pages

Program 27

The document provides a C program that defines a student structure and implements various operations such as displaying student details, computing results, searching by roll number, and finding students with maximum and minimum marks. It utilizes functions for each operation and dynamically allocates memory for storing student data. The program allows interaction through a menu-driven interface for user input and displays the results accordingly.

Uploaded by

jhapushpam.work
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

Program 27:WAP to create a student structure and perform the following

operations:
1. Show the details of 15 students.
2. Display all or one.
3. Compute the result of all students.
4. Linear search based on roll no.
5. Find and display the name and roll no of students with max and min marks.

Use functions for all operations (call by value and call by address).

Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char name[100];
int rollno;
int marks[5];
int total;
float avg;
} student;
void display(student[], int);
void results(student[], int);
void search(student[], int);
void minimum_maximum(student[], int);
int main(void)
{
int a, b,inp,i,j;
float avg;
student *s1;
printf("Enter Number Of Students: ");
scanf("%d", &a);
s1 = (student *)calloc(a, sizeof(student));

for (b = 0; b < a; b++)


{
printf("For Student %d\n", (b + 1));
printf("Enter Name: ");
scanf("%s", &s1[b].name);
printf("Enter Roll Number: ");
scanf("%d", &s1[b].rollno);
for (i = 0; i < 5; i++)
{
printf("Enter Marks %d: ", (i + 1));
scanf("%d", &s1[b].marks[i]);
}
s1[b].total = 0;
s1[b].avg = 0;
for (j = 0; j < 5; j++)
{
s1[b].total += s1[b].marks[j];
}
s1[b].avg = (s1[b].total / 5.0);
printf("\n");
}
while (inp != 5)
{
printf("\[Link] All Students \[Link] Results \[Link] Roll Number \[Link]
Student With Max & Min Marks \[Link] \n");

printf("What Do You Want To Do? : ");


scanf("%d", &inp);
switch (inp)
{
case 1:
display(s1, a);
break;
case 2:
results(s1, a);
break;
case 3:
search(s1, a);
break;
case 4:
minimum_maximum(s1, a);
break;
default:
printf("Try Again !! \n");
break;
}
}

free(s1);
}
void display(student s1[], int a)
{
int f;
for (f = 0; f < a; f++)
{
printf("For Student %d\n", (f + 1));
printf("Name Of The Student: %s \nRoll Number: %d \nTotal Marks: %d \nAverage Marks: %.2f
\n", s1[f].name, s1[f].rollno, s1[f].total, s1[f].avg);
}
}
void results(student s1[], int a)
{
int f;
for (f = 0; f < a; f++)
{
if (s1[f].total > 200)
{
printf("Student %d : Passed\n", (f + 1));
}

else
{
printf("Student %d : Failed\n", (f + 1));
}
}
}
void search(student s1[], int a)
{
int flag = 0, f, roll;
printf("Enter Roll Number: ");
scanf("%d", &roll);
for (f = 0; f < a; f++)
{
if (s1[f].rollno == roll)
{
printf("Name Of The Student: %s \nRoll Number: %d \nTotal Marks: %d \nAverage Marks:
%.2f \n", s1[f].name, s1[f].rollno, s1[f].total, s1[f].avg);
flag = 1;
}
}
if (flag == 0)
{
printf("Not Found\n");
}
}
void minimum_maximum(student s1[], int a){
int min = 500, max = 0, f, z;
printf("THIS fUNCTION IS RUNNING");
for (f = 0; f < a; f++)
{
if (s1[f].total > max)
{
max = s1[f].total;
}
if (s1[f].total < min)
{
min = s1[f].total;
}
}
for (z = 0; z < a; z++)
{
if (max == s1[z].total)
printf("Max Marks: \nName Of Student: %s\nRoll Number: %d\nTotal Marks: %d\n",
s1[z].name, s1[z].rollno, s1[z].total);
if (min == s1[z].total)
printf("Min Marks: \nName Of Student: %s\nRoll Number: %d\nTotal Marks: %d\n",
s1[z].name, s1[z].rollno, s1[z].total);
}
printf("Line 156 is Working !!");

}
OUTPUT:

You might also like