Showing posts with label multi link list. Show all posts
Showing posts with label multi link list. Show all posts

Monday, May 23, 2016

WAP to implement multi link list of student record.

#include<stdio.h>
#include<conio.h>
struct marks
{
int subno,mrk;
struct marks *next;
}*mtemp,*mtemp1;
struct stud
{
int rno,tot;
float per;
struct marks *link;
struct stud *next;
}*first,*temp,*temp1;
void display()
{
if(first==NULL)
{
printf("No records");
return;
}
temp=first;
while(temp!=NULL)
{
printf("\nRollno : %d",temp->rno);
mtemp=temp->link;
while(mtemp!=NULL)
{
printf("\nSubno : %d\tmarks: %d",mtemp->subno,mtemp->mrk);
mtemp=mtemp->next;
}
printf("\nTotal : %d\tPercentage: %f%",temp->tot,temp->per);
temp=temp->next;
}

}
void main()
{
char mch,ch;
int cnt;
clrscr();
do
{
temp=(struct stud*)malloc(sizeof(struct stud));
printf("Enter rollno: ");
scanf("%d",&temp->rno);
temp->next=NULL;
temp->link=NULL;
cnt=0;
do
{
mtemp=(struct marks*)malloc(sizeof(struct marks));
printf("Enter subno: ");
scanf("%d",&mtemp->subno);
printf("Enter marks: ");
scanf("%d",&mtemp->mrk);
if(temp->link==NULL)
{
temp->link=mtemp;
temp->tot=mtemp->mrk;
}
else
{
mtemp1->next=mtemp;
temp->tot=temp->tot+mtemp->mrk;
}
mtemp->next=NULL;
mtemp1=mtemp;
cnt++;
fflush(stdin);
printf("\nDo you want Enter more sub marks: ");
scanf("%c",&mch);
}while(mch=='y' || mch=='Y');
temp->per=temp->tot/cnt;
if(first==NULL)
first=temp;
else
temp1->next=temp;
temp->next=NULL;
temp1=temp;
fflush(stdin);
printf("\nDo you want Enter more students: ");
scanf("%c",&ch);
}while(ch=='y' || ch=='Y');
display();
getch();
}