Structure is a complex data type used to group related data of different data types. Usually structure is used to store records.To process more than one record, an array of structures is created. The following program process the result of students using array of structures.
//Program to process student result
#include<stdio.h>
#include<conio.h>
struct student
{
int stdno,m[20],total;
float avg;
char name[10];
}s[10];
main()
{
int i,j,n,p,sum=0;
clrscr();
printf("Enter the students details\n");
printf("Enter the total number of students for whom the details are required\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter student %d details\n",i+1);
printf("Enter the students register number:\t");
scanf("%d",&s[i].stdno);
printf("Enter the name of the student:\t");
scanf("%s",s[i].name);
printf("Enter the total number of subjects;\t");
scanf("%d",&p);
sum=0;
for(j=0;j<p;j++)
{
printf("Enter the marks of subject %d\n",j+1);
scanf("%d",&s[i].m[j]);
sum=sum+s[i].m[j];
}
s[i].total=sum;
s[i].avg=s[i].total/j;
}
for(i=0;i<n;i++)
{
printf("\nStudent %d details",i+1);
printf("\n--------------------------");
printf("\nName of the student:%s ",s[i].name);
printf("\nRegister number :%d ",s[i].stdno);
for(j=0;j<p;j++)
printf("\nSubject[%d] Mark = %d\t",j+1,s[i].m[j]);
printf("\nTotal marks;%d ",s[i].total);
printf("\nAverage marks:%f\n",s[i].avg);
getch();
}
}
/*
OUTPUT
-------
Enter the students details
Enter the total number of students for whom the details are required 2
Enter student 1 details
Enter the students register number: 1
Enter the name of the student: ss
Enter the total number of subjects; 3
Enter the marks of subject 1
1
Enter the marks of subject 2
2
Enter the marks of subject 3
3
Enter student 2 details
Enter the students register number: 2
Enter the name of the student: sa
Enter the total number of subjects; 3
Enter the marks of subject 1
1
Enter the marks of subject 2
1
Enter the marks of subject 3
1
Student 1 details
--------------------------
Name of the student:ss
Register number :1
Subject[1] Mark = 1
Subject[2] Mark = 2
Subject[3] Mark = 3
Total marks;6
Average marks:2.000000
Student 2 details
--------------------------
Name of the student:sa
Register number :2
Subject[1] Mark = 1
Subject[2] Mark = 1
Subject[3] Mark = 1
Total marks;3
Average marks:1.000000
*/
//Program to process student result
#include<stdio.h>
#include<conio.h>
struct student
{
int stdno,m[20],total;
float avg;
char name[10];
}s[10];
main()
{
int i,j,n,p,sum=0;
clrscr();
printf("Enter the students details\n");
printf("Enter the total number of students for whom the details are required\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter student %d details\n",i+1);
printf("Enter the students register number:\t");
scanf("%d",&s[i].stdno);
printf("Enter the name of the student:\t");
scanf("%s",s[i].name);
printf("Enter the total number of subjects;\t");
scanf("%d",&p);
sum=0;
for(j=0;j<p;j++)
{
printf("Enter the marks of subject %d\n",j+1);
scanf("%d",&s[i].m[j]);
sum=sum+s[i].m[j];
}
s[i].total=sum;
s[i].avg=s[i].total/j;
}
for(i=0;i<n;i++)
{
printf("\nStudent %d details",i+1);
printf("\n--------------------------");
printf("\nName of the student:%s ",s[i].name);
printf("\nRegister number :%d ",s[i].stdno);
for(j=0;j<p;j++)
printf("\nSubject[%d] Mark = %d\t",j+1,s[i].m[j]);
printf("\nTotal marks;%d ",s[i].total);
printf("\nAverage marks:%f\n",s[i].avg);
getch();
}
}
/*
OUTPUT
-------
Enter the students details
Enter the total number of students for whom the details are required 2
Enter student 1 details
Enter the students register number: 1
Enter the name of the student: ss
Enter the total number of subjects; 3
Enter the marks of subject 1
1
Enter the marks of subject 2
2
Enter the marks of subject 3
3
Enter student 2 details
Enter the students register number: 2
Enter the name of the student: sa
Enter the total number of subjects; 3
Enter the marks of subject 1
1
Enter the marks of subject 2
1
Enter the marks of subject 3
1
Student 1 details
--------------------------
Name of the student:ss
Register number :1
Subject[1] Mark = 1
Subject[2] Mark = 2
Subject[3] Mark = 3
Total marks;6
Average marks:2.000000
Student 2 details
--------------------------
Name of the student:sa
Register number :2
Subject[1] Mark = 1
Subject[2] Mark = 1
Subject[3] Mark = 1
Total marks;3
Average marks:1.000000
*/
No comments:
Post a Comment