How to use passing structure

/* write c prgram to define a structure name “student” having
members seat_no,name,marks,& per. Sub are english,c,pcs,fco,maths, Total,Percentage*/
#include<stdio.h>
#include<conio.h>
struct student
{
int seat_no,t,m[5];
char name[20],sub_name[5][20];
float p;
};
void input(struct student);
void output(struct student);
void main()
{
struct student s;
clrscr();
input(s);
getch();
}
void input(struct student x)
{
int i;
printf(“enter seat no:”);
scanf(“%d”,&x.seat_no);
fflush(stdin);
printf(“enter student name:”);
scanf(“%s”,&x.name);
for(i=0;i<5;i++)
{
printf(“enter sub_name:”);
scanf(“%s”,&x.sub_name[i]);
fflush(stdin);
printf(“enter sub marks:”);
scanf(“%d”,&x.m[i]);
x.t=x.t+x.m[i];
}
output(x);
}
void output(struct student y)
{
int i;
printf(“seat_no:%d”,y.seat_no);
printf(“name:%s”,y.name);
printf(“\n__________________\n”);
printf(“sub name|sub marks\n”);
printf(“__________________\n”);
for(i=0;i<5;i++)
{
printf(“%s\t|%d\t|\n”,y.sub_name[i],y.m[i]);
}
printf(“total\t|%d\t|”,y.t);
printf(“\npercentage\t|%f\t|”,(y.t)/5.0);
}

Leave a Reply

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