Advertisement
Guest User

stack

a guest
Nov 1st, 2010
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct pointer{
  5.   int info;
  6.   struct pointer *link;
  7. } MyType;
  8. MyType *l,*p;
  9. const n=4;
  10. int d,i;
  11. float s;
  12. main()
  13. {
  14.   l=NULL;
  15.   for(i=1;i<=n;i++)
  16.   {
  17.     p=(MyType *)malloc(sizeof(MyType));
  18.     printf("\nPhantu %d:",i);
  19.     scanf("%d",&p->info);
  20.     if(l==NULL)
  21.     {
  22.       p->link = NULL;
  23.       l=p;
  24.     }
  25.     else {
  26.       p->link =l;
  27.       l=p;
  28.     }}
  29.     s=0;
  30.     d=0;
  31.     p=l;
  32.     while(p!=NULL)
  33.     {
  34.       if(p->info %2 ==0)
  35.       {
  36.     d++;
  37.     s=s+p->info;
  38.       }
  39.       p=p->link;
  40.     }
  41.     if(d!=0) printf("TBC = %f", s/d);
  42.     else printf("Khong co phan tu nao chia het cho 2");
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement