#include <stdio.h>
#include <conio.h>
typedef struct node
{
        int data;
        node *next;
};
void xem(node *first)
{
     node *p;
     p=first;
     while(p!=NULL)
     {
                   printf("%d",p->data);
                   p=p->next;
     }
}
node *nhap(node *first,int n)
{
     node *p;
     for(int i=0;i<n;i++)
     {
             p=new(node);
             scanf("%d",&p->data);
             p->next=first;
             first=p;
     }
     return first;
}
int demnodechan(node *first)
{
     node *p;
     p=first;
     int dem=0;
     while(p!=NULL)
     {
                   if(p->data%2==0)
                   dem++;
                   p=p->next;
     }
     return dem++;
}

int tongnode(node *first)
{
     node *p;
     p=first;
     int dem=0;
     while(p!=NULL)
     {
                   dem+=p->data;
                   p=p->next;
     }
     return dem;
}
main()
{
      int n;
      node *first=NULL,*p=NULL;
      printf("\nnhap n la :\n");
      scanf("%d",&n);
      first=nhap(first,n);
      printf("\nxem: ");
      xem(first);
      printf("\ndem node co gia tri chan la %d",demnodechan(first));
      printf("\ntong node la %d",tongnode(first));
      getch();
}
//code by :Doan Tu Tai

Bài viết liên quan

Không có nhận xét nào:

Đăng nhận xét