C program to Print Student Result using Array of Structure

C program to Print Student Result using Array of Structure:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
struct stud
{
 int roll_no;
 char name[15];
 int m1,m2,m3;
 int total;
 float per;
}s[3];

 main()
{
 int i;
 void line();
 for(i=0;i<3;i++)
 {
  printf("Enter %d students record\n",i+1);
  printf("Roll No:");
  scanf("%d",&s[i].roll_no);
  printf("\n");
  printf("Name:");
  scanf("%s",s[i].name);
  printf("Mark of first subject:");
  scanf("%d",&s[i].m1);
  printf("\n");
  printf("Mark of second subject:");
  scanf("%d",&s[i].m2);
  printf("\n");
  printf("Mark of third subject:");
  scanf("%d",&s[i].m3);
  printf("\n");
 }
 for(i=0;i<3;i++)
 {
  s[i].total=s[i].m1+s[i].m2+s[i].m3;
  s[i].per=s[i].total/3.0;
 }

 printf("The student Marks details..\n");
 line();
 printf("Roll No\tName\tMark1\tMark2\tMark3\tTotal\tPercentage\n");
 line();
 for(i=0;i<3;i++)
 {
  printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\n",s[i].roll_no,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].per);
  line();
 }
}
 void line()
 {
  int i;
  for(i=0;i<80;i++)
  {
   printf("-");
  }
    printf("\n");
 }

OUTPUT:

Enter 1 students record
Roll No:1

Name:John
Mark of first subject:45

Mark of second subject:75

Mark of third subject:52

Enter 2 students record
Roll No:2

Name:Willam
Mark of first subject:45

Mark of second subject:75

Mark of third subject:65

Enter 3 students record
Roll No:3

Name:Rahul
Mark of first subject:45

Mark of second subject:75

Mark of third subject:85

The student Marks details..
--------------------------------------------------------------------------------
Roll No Name    Mark1   Mark2   Mark3   Total   Percentage
--------------------------------------------------------------------------------
1       John    45      75      52      172     57.333332
--------------------------------------------------------------------------------
2       Willam  45      75      65      185     61.666668
--------------------------------------------------------------------------------
3       Rahul   45      75      85      205     68.333336
--------------------------------------------------------------------------------

 

Leave a Reply

Your email address will not be published. Required fields are marked *

twelve − one =