1.2 tạo danh sách lifo gầm các số thực. xem danh sách, và đếm số các số thực trong dánh sách lớn hơn 3.14.

Thursday, November 27, 2014

#include <stdio.h>
#include <conio.h>
typedef struct node
{
      float info;
      node *link;
};
node *nhap(node *f,node *l,int n)
{
      node *p;
      int i;
      for (i=0;i<n;i++)
      {
            p=new(node);
            scanf("%f",&p->info);
            p->link=NULL;
            if (f==NULL) {f=p; l=p;}
            else {l->link=p; l=p;}
      }
      return f;
}
void xem(node *f)
{
      node *p;
      p=f;
      while (p!=NULL)
      {
            printf("%5.2f",p->info);
            p=p->link;
      }
}
int Dem(node *f)
{
      node *p;
      p=f;
      int dem=0;
      while (p!=NULL)
      {
            if (p->info>3.14) dem++;
            p=p->link;
      }
      return dem;
}
int main()
{
      int n;
      node *f=NULL,*l=NULL;
      printf("\n N =  ");
      scanf("%d",&n);
      f=nhap(f,l,n);
      xem(f);
      printf("\n So luong so > 3,14 la : %d ",Dem(f));
      getch();
}
Chia sẻ bài viết ^^
Other post

All comments [ 3 ]


1
Unknown November 7, 2015 at 8:46 AM

#include
#include
typedef struct NODE
{ int info;
NODE *next;
}NODE;
// ham tao danh sach don LIFO
NODE *taoLIFO(NODE *first)
{ int n, i; printf("Nhap so phan tu : n = "); scanf("%d", &n);
NODE *p;
for(i=0;iinfo);
if(first==NULL)
{ first=p;
p->next=NULL;
}
else
{ p->next=first;
first=p;
}
return first;
}
}
// ham xem noi dung danh sach ra man hinh
void xemds(NODE *first)
{ NODE *p;
p=first;
while(p!=NULL)
{ printf("%5d", p->info);
p=p->next;
}
}

2
Unknown November 7, 2015 at 9:05 AM

đây là fifo rồi. không phải lifo

3
Unknown November 12, 2021 at 4:24 PM

bài fifo này chuyển sang lifo như thế nào ạ, ad giúp em với ạ

#include
#include
#include
#include
struct Phanso
{
int tu , mau;
};
struct Node
{
Phanso ps;
Node* next;
};
void nhap(Phanso &x)
{

printf("nhap tu: ");
scanf("%d",&x.tu);
printf("nhap mau: ");
scanf("%d",&x.mau);
}
void xuat(Phanso &x)
{

printf("\n %d/%d",x.tu ,x.mau);

}

Node* taoNode(Phanso dl)
{
Node* tamthoi = new Node();
tamthoi->ps = dl;
tamthoi->next = NULL;
return tamthoi;
}
Node* themNode(Node* t, Node* p)
{
Node* tmp;
if (t == NULL)
t = p;
else
{
tmp = t;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = p;
}
return t;
}
////
void inNode(Node* t)
{
Node* tmp = t;

while (tmp != NULL)
{
xuat(tmp->ps);
tmp = tmp->next;
}
}
/////
Node* LienKetDon(int n)
{
Phanso x;
Node* t = NULL;
for (int i = 1; i <= n; i++)
{
Node* p =NULL;
printf("phan so thu [%d] : ", i);
nhap(x);
p = taoNode(x);
t = themNode(t, p);
}
return t;
}

main()
{
int n;
Node* lkd = NULL;
printf("so cac phan so :");
scanf("%d", &n);
lkd = LienKetDon(n);
printf("\n cac phan so \n");
inNode(lkd);

}

Your comments