Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Dem so phan tu duong trong day
- #include<stdio.h>
- #include<stdlib.h>
- //khai bao thu vien
- typedef struct pointer
- {
- int info;
- struct pointer *link;
- } MyType;
- //khai bao cau truc
- MyType *l,*p;
- const n=4;
- int d,i;
- //khai bao bien
- void main() //chuong trinh
- {
- l=NULL;
- for(i=1;i<=n;i++)
- {
- p=(MyType *)malloc(sizeof(MyType)); //tao bien dong p va cap bo nho cho p
- printf("\n Phantu %d: ",i);
- scanf("%d",&p->info); // ghi vao info cua p
- if(l==NULL)
- {
- p->link = NULL;
- l=p;
- }
- else {
- p->link =l;
- l=p;
- }
- }
- d=0;
- p=l;
- while(p!=NULL)
- {
- if(p->info > 0) //tim phan tu duong
- d++; // voi moi phan tu duong tim thay tang d len 1
- p=p->link;
- }
- if(d!=0) printf("Day co %d phan tu duong", d);
- else printf("Day da nhap khong co phan tu duong");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement