0% found this document useful (0 votes)
6 views

PPS_Assignment_7_Array

The document contains a C program for accepting and displaying student details using an array of structures. It defines a 'Student' structure to hold roll number, marks, name, total, and percentage, and includes functionality to calculate and display results. The program outputs whether each student has passed or failed based on their percentage.

Uploaded by

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

PPS_Assignment_7_Array

The document contains a C program for accepting and displaying student details using an array of structures. It defines a 'Student' structure to hold roll number, marks, name, total, and percentage, and includes functionality to calculate and display results. The program outputs whether each student has passed or failed based on their percentage.

Uploaded by

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

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:

You might also like