Trang chủ
/ bai tap fifo
/ bai tap lien ket mang
/ bai tap lifo
/ bai tập fifo
/ bài tập lifo
/ cau truc du lieu va giai thuat
/ fifo
/ giải thuật
/ lập trình C
/ liên kết fifo
/ liên kết lifo
/ lifo
/Bài tập LIFO:Nhập mảng-xem mảng-đếm node chẵn-tổng các node trong danh sách
#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
Không có nhận xét nào:
Đăng nhận xét