C Programming Ex9
C Programming Ex9
PROCEDURE:
Step 1:
Start
Step 2:
Declare the structure using the struct keyword
Step 3:
Read the number of students
Step 4:
Using the loop read the student information like regno, name
and three subject mark
Step 5: calculate the total and average for all the student
Step 5: Display all the information
Step 7: Stop
PROGRAM:
#include <stdio.h>
#include <conio.h>
struct student {
char name[50];
int roll;
int m1,m2,m3,total;
float avg;
} s[5];
void main() {
int i,n;
clrscr();
rintf("Enter Number of Students : ");
scanf("%d",&n);
printf("Enter information for %d students:\n",n);
for(i=0;i<n;i++)
{
s[i].roll = i + 1;
printf("\n For roll number %d,\n", s[i].roll);
printf("Enter name: ");
scanf("%s", s[i].name);
printf("Enter marks 3 subject Marks ");
scanf("%d", &s[i].m1);
scanf("%d", &s[i].m2);
scanf("%d", &s[i].m3);
}
printf("Displaying Information:\n\n");
printf("\n R.No \t Name \t Total \t Average");
for (i = 0; i < n; ++i) {
s[i].total = s[i].m1+s[i].m2+s[i].m3;
s[i].avg = s[i].total /3.0;
printf("\n %d\t\t %s\t %d \t %.2f",s[i].roll,s[i].name, s[i].total,
s[i].avg);
}
getch();
}
RESULTS:
Thus, the C program to collect and print students' details using
structure was successfully executed.