c program to calculate 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.
PROGRAM
#include stdio.h //put is <>in header file
#include conio.h
struct student
{
int rollno,tot;
char name[25];
int mark[5];
};
void main()
{
struct student s[5]; //Data type of ‘*s’ is struct student
int i,n,j;
clrscr();
printf(“Enter the number of students:”);
scanf(“%d”,&n);
printf(“\t*Students Records*\n”);
//take input from user
for(i=0;i<n;i++)
{
printf("\nEnter Student Roll Number: ");
scanf("%d",&s[i].rollno);
printf("\nEnter Student name: ");
scanf("%s",s[i].name);
printf("\nEnter Student 3 subject's marks: ");
for(j=0;j<3;j++)
scanf("%d",&s[i].mark[j]);
}
//calculation
for(i=0;i<n;i++)
{
s[i].tot=0;
for(j=0;j<3;j++)
s[i].tot = s[i].tot+ s[i].mark[j];
}
//Display result
for(i=0;i<n;i++)
{
printf("\t*Students Records*\n");
printf("\n==================================\n");
printf("\nStudent's Roll no. – %d", s[i].rollno);
printf("\nStudent's Name – %s", s[i].name);
printf("\nStudent's Total Marks – %d", s[i].tot);
}
getch();
}
OUTPUTEnter the number of students:2
*Students Records*
Enter Student Roll Number: 01
Enter Student name: rathi
Enter Student 3 subject’s marks:
12
67
89
Enter Student Roll Number: 02
Enter Student name: kishore
Enter Student 3 subject’s marks:
56
89
90
*Students Records*
==================================
Student’s Roll no. – 1
Student’s Name – rathi
Student’s Total Marks – 168 *Students Records*
==================================
Student’s Roll no. – 2
Student’s Name – kishore
Student’s Total Marks – 235

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s