You are on page 1of 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