Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by hiutrun ( 6 years ago )
#include<stdio.h>
#include<stdlib.h>

struct sinhvien
{
    char mssv[30];
    char hoten[50];
    char gioitinh[5];
    float diemTB;
};
typedef struct sinhvien SV;

typedef struct node
{
    SV sv;
    struct NODE *pNext; 
}NODE;

typedef struct list
{
     NODE *pHead;
     NODE *pTail;
}LIST;

void CreateList(LIST *l)
{
    l->pHead = NULL;
    l->pTail = NULL;
}

NODE* CreatedNODE(SV sv)
{
    NODE *p = (NODE*)malloc(sizeof(NODE)) ;
    p->sv = sv;
    p->pNext = NULL;
    return p;
}

void AddTail(LIST *l, NODE *p)
{
    if(l->pHead == NULL)
    {
        l->pHead = l->pTail = p;
    }
    else
    {
        l->pTail->pNext = p;
        l->pTail = p;
    }
}

void nhapSV(SV *sv)
{
    fflush(stdin);
    gets(sv->mssv);
    fflush(stdin);
    gets(sv->hoten);
    fflush(stdin);
    gets(sv->gioitinh);
    scanf("%f",&sv->diemTB);
    
}

void nhap(LIST *l)
{
    SV sv;
    int n;
    printf("\Nhap so sinh vien: ");
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        nhapSV(&sv);
        NODE *p = CreatedNODE(sv);
        AddTail(l,p);
    }
}
void XuatSV(SV sv)
{
    printf("%10s\t%20s\t%5s\t%8.2f",sv.mssv,sv.hoten,sv.gioitinh,sv.diemTB);
    printf("\n");
}
void xuat(LIST L)
{
    NODE *p;
    p = L.pHead;
    while(p!=NULL)
    {
        XuatSV(p->sv);
        p=p->pNext;
    }
	
}

int main()
{
    LIST l;
    CreateList(&l);
    nhap(&l);
    printf("Xuat\n");
    xuat(l);

    return 0;
}

 

Revise this Paste

Your Name: Code Language: