Guest User

Untitled

a guest
Nov 2nd, 2010
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Dem so phan tu duong trong day
  2.  
  3.  
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6. //khai bao thu vien
  7. typedef struct pointer
  8. {
  9.   int info;
  10.   struct pointer *link;
  11. } MyType;
  12. //khai bao cau truc
  13.  
  14. MyType *l,*p;
  15. const n=4;
  16. int d,i;
  17.  
  18. //khai bao bien
  19. void main() //chuong trinh
  20. {
  21.   l=NULL;
  22.   for(i=1;i<=n;i++)
  23.   {
  24.     p=(MyType *)malloc(sizeof(MyType)); //tao bien dong p va cap bo nho cho p
  25.     printf("\n Phantu %d: ",i);
  26.     scanf("%d",&p->info); // ghi vao info cua p
  27.     if(l==NULL)
  28.     {
  29.       p->link = NULL;
  30.       l=p;
  31.     }
  32.     else {
  33.       p->link =l;
  34.       l=p;
  35.     }
  36.     }
  37.    
  38.     d=0;
  39.     p=l;
  40.     while(p!=NULL)
  41.     {
  42.       if(p->info > 0) //tim phan tu duong
  43.     d++; // voi moi phan tu duong tim thay tang d len 1
  44.     p=p->link;
  45.     }
  46.     if(d!=0) printf("Day co %d phan tu duong", d);
  47.     else printf("Day da nhap khong co phan tu duong");
  48.  
  49. }
RAW Paste Data