0% found this document useful (0 votes)
20 views4 pages

Practical 9

The document contains two C programs that demonstrate the use of structures to manage student data. The first program creates a structure for student roll numbers and names, displaying the records for two students. The second program expands on this by including student names, marks in five subjects, and calculates their percentage and result class based on their performance.

Uploaded by

dshefali3
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)
20 views4 pages

Practical 9

The document contains two C programs that demonstrate the use of structures to manage student data. The first program creates a structure for student roll numbers and names, displaying the records for two students. The second program expands on this by including student names, marks in five subjects, and calculates their percentage and result class based on their performance.

Uploaded by

dshefali3
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/ 4

9.1 Write a Program to create structure of student’s roll no.

and name and


display the records.
#include <stdio.h>
struct student
{
int rollno;
char name[20];
};
int main()
{
struct student s1 = {1, "Mansi"}, s2 = {2, "Nirav"};
printf("\nStudent Data:");
printf("\nRoll No\tName");
printf("\n%d\t%s", s1.rollno, s1.name);
printf("\n%d\t%s", s2.rollno, s2.name);
return 0;
}
OUTPUT:
Student Data:
Roll No Name
1 Mansi
2 Nirav
9.2 Write a Program to create structure of student with name and result in 5
subjects. Display the appropriate result class along with student’s name for n
students.
#include <stdio.h>
#include <string.h> // Required for strcpy()
struct result {
char name[30];
int marks[5];
float percentage;
char resultclass[15];
} student[100];

int main() {
int i, n, j;
float sum;
printf("\nHow many students' data do you want to enter (Maximum 100)? ");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
sum = 0;
printf("\nStudent %d's data:\n", i + 1);
printf("Enter Student's Name: ");
scanf("%s", student[i].name);
for(j = 0; j < 5; j++)
{
printf("Enter Marks in Subject %d: ", j + 1);
scanf("%d", &student[i].marks[j]);
sum += student[i].marks[j];
}

student[i].percentage = sum / 5.0;


if(student[i].percentage < 40)
strcpy(student[i].resultclass, "Fail");
else if(student[i].percentage <= 50)
strcpy(student[i].resultclass, "Pass Class");
else if(student[i].percentage <= 60)
strcpy(student[i].resultclass, "Second Class");
else if(student[i].percentage <= 66)
strcpy(student[i].resultclass, "First Class");
else
strcpy(student[i].resultclass, "Distinction");
}

printf("\nResult of All Students:\n");


printf("\n%-15s %-10s %-15s\n", "Name", "Percentage", "Result Class");
for(i = 0; i < n; i++)
{
printf("%-15s %-10.2f %-15s\n", student[i].name, student[i].percentage,
student[i].resultclass);
}
return 0;
}
OUTPUT:
How many student’s data you want to enter (Maximum 100) : 2
Student 1’s data :
Enter Student’s Name : SIYA
Enter Student’s Marks in Subject 1 : 40
Enter Student’s Marks in Subject 2 : 60
Enter Student’s Marks in Subject 3 : 50
Enter Student’s Marks in Subject 4 : 40
Enter Student’s Marks in Subject 5 : 70
Student 2’s data :
Enter Student’s Name : HIYA
Enter Student’s Marks in Subject 1 : 50
Enter Student’s Marks in Subject 2 : 40
Enter Student’s Marks in Subject 3 : 60
Enter Student’s Marks in Subject 4 : 70
Enter Student’s Marks in Subject 5 : 40
Result of All Students………….
Name Percentage ResultClass
SIYA 52 Second Class
HIYA 52 Second Class

You might also like