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

QUESTION Lab Work 11

The document describes a C program to calculate the total marks and average marks of N students using an array of structures. 1. It defines a student structure with name, roll number, and marks fields and declares an array of structures. 2. It inputs the student details like name, roll number and marks using a for loop and calculates the total marks. 3. It displays the student details and calculates the average marks by summing the total marks and dividing by N.

Uploaded by

Lovekush Kumar
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)
70 views6 pages

QUESTION Lab Work 11

The document describes a C program to calculate the total marks and average marks of N students using an array of structures. 1. It defines a student structure with name, roll number, and marks fields and declares an array of structures. 2. It inputs the student details like name, roll number and marks using a for loop and calculates the total marks. 3. It displays the student details and calculates the average marks by summing the total marks and dividing by N.

Uploaded by

Lovekush Kumar
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/ 6

LAB WORK 10

QUESTION:- Implement structures to read, write and compute average-


marks and the students scoring above and below the average marks for a
class of N students.
Objective(s):
C PROGRAM TO CALCULATE TOTAL MARKS USING ARRAY OF
STRUCTURES
Program: Write a Program to calculate and display TOTAL MARKS USING ARRAY
OF STRUCTURES

Algorithm:
1. Start the program.
2. Declare a structure student with variables name, roll no, mark, tot.
3. Declare the necessary variables.
4. Create a structure variable using arrays.
5. Get the student roll no, name, mark using for loop.
6. Calculate the total marks using arithmetic operator.
7. Using for loop display name, roll no and total for each student.
8. Stop the program.
Flowchart:
LAB WORK 10
LAB WORK 10

Code:

//Following code is written and compiled in GCC


#include <stdio.h>
#include <stdlib.h>
#include<math.h>
struct student {
char first_name[50];
char last_name[50];
int roll_number;
float marks;
} s[100];
int main() {
int x, i;
float avgmarks,total=0;
printf("Enter the number of students: ");
scanf("%d", &x);
printf("\nEnter the students's informations:\n");
for (i = 0; i < x; i++) {
s[i].roll_number = i + 1;
printf("\nInformation for Roll Number:\t%d\n", s[i].roll_number);
printf("Enter the first name: ");
scanf("%s", s[i].first_name);
printf("Enter the last name: ");
scanf("%s", s[i].last_name);
LAB WORK 10

printf("Enter the marks: ");


scanf("%f", &s[i].marks);
}
printf("\n\nDisplay the student's information:\n");
for (i = 0; i < x; i++) {
printf("\nThe Roll Number:\t%d\n", i + 1);
printf("The First Name: ");
puts(s[i].first_name);
printf("The Last Name: ");
puts(s[i].last_name);
printf("The Marks: %.1f", s[i].marks);
printf("\n");
}
for(i=0;i<x;i++)
{
total = total + s[i].marks;
}
avgmarks=total/x;
printf("\nAverage marks = %.2f",avgmarks);

return 0;
}
N=2.
input: 70,80.
LAB WORK 10

output: 70,80,75.
LAB WORK 10

You might also like