Name Abhishek Sahoo
PRN 1262242426
Division: 24 Batch: 2
Subject Programming and Problem Solving (PPS)
Subject Code CSE10120
Assignment No. 7
Problem Statement:
Write a C program to accept student details and display their result using an array of structures.
Code:
#include <stdio.h>
struct Student {
int roll;
int m1, m2, m3;
char name[30];
int total;
float per;
};
int main() {
int i, n;
printf("--------Student Information--------\n");
printf("Enter the number of records: ");
scanf("%d", &n);
struct Student strarr[n]; // Declaring an array of 'n' students.
for (i = 0; i < n; i++) {
printf("Enter the roll no of student %d: ", i + 1);
scanf("%d", &strarr[i].roll);
printf("Enter the marks of 3 subjects: ");
scanf("%d %d %d", &strarr[i].m1, &strarr[i].m2, &strarr[i].m3);
printf("Enter the name of the student: ");
scanf("%s", strarr[i].name);
// Calculating total and percentage
strarr[i].total = strarr[i].m1 + strarr[i].m2 + strarr[i].m3;
strarr[i].per = (float)strarr[i].total / 3; // Use floating
point division for percentage
}
// Print header for result
printf("\nRoll No |\tName\t|\tMarks 1|\tMarks 2|\tMarks 3|\tTotal\t|
Percentage\t|Result\n");
printf("-----------------------------------------------------------------
------------------------\n");
// Print student results
for (i = 0; i < n; i++) {
printf("%d\t|\t%-15s|\t%d\t|\t%d\t|\t%d\t|\t%d\t|\t%.2f\t|\t",
strarr[i].roll, strarr[i].name, strarr[i].m1, strarr[i].m2, strarr[i].m3,
strarr[i].total, strarr[i].per);
// Print Pass or Fail based on percentage
if (strarr[i].per < 20) {
printf("Fail\n");
} else {
printf("Pass\n");
}
}
return 0;
}
Output: