Anh/chị giúp em đoạn code nay với. Đề bài yêu cầu là tìm số nguyên tố lớn nhất,khả năng em làm chỉ tới đây thôi ạ. Nhờ anh/chị giúp em, em xin cám ơn ạ ^^
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
node *next;
};
struct list
{
node *head;
node *tail;
};
node *getnode(int x)
{
node *p;
p=new(node);
if(p==NULL)
{
printf("\n khong du bo nho");
return NULL;
}
p->data=x;
p->next=NULL;
return p;
}
void Init(list &l)
{
l.head=l.tail=NULL;
}
void addtail(list &l,node *new_e)
{
if(l.head==NULL)
l.head=l.tail=new_e;
else
l.tail->next=new_e;
l.tail=new_e;
}
void Nhap (list &l)
{
int i,x,n;
node *p;
printf("Nhap so luong: ");scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n a[%d]: ",i);
scanf("%d",&x);
p=getnode(x);
addtail(l,p);
}
}
void Xuat(list &l)
{
node *p;
p=l.head;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
void them_dau(list &l,node * new_e)
{
node *p;
if(l.head==NULL)
l.head=l.tail=new_e;
else
{
new_e->next=l.head;
l.head=new_e;
}
}
void them_cuoi(list &l,node *new_e)
{
if(l.head==NULL)
l.head=l.tail=new_e;
else
{
l.tail->next=new_e;
l.tail=new_e;
}
}
int max(list l)
{
node *p;
int solonnhat;
solonnhat=l.head->data;
p=l.head;
while(p!=NULL)
{
if(solonnhat < p->data)
{
solonnhat=p->data;
}
else
{
p=p->next;
}
}
return solonnhat;
}
int main()
{
int solon;
int chan;
list l;
node *p;
Init (l);
Nhap(l);
Xuat(l);
}