Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- ifstream f("date.in");
- ofstream g("date.out");
- struct nod
- {
- int info;
- nod *adr;
- };
- nod *prim;
- int nrprim(int x)
- {
- int i,ok=1;
- for (i=2;i<=sqrt(x);i++)
- if (x%i==0)
- ok=0;
- if (ok==1)
- return 1;// e prim
- return 0;// nu e prim
- }
- void creare()
- {
- int n,i;
- nod *p,*nou;
- while (f>>n)
- if (prim==NULL)
- {
- prim=new nod;
- prim->info=n;
- p=prim;
- }
- else
- {
- nou=new nod;
- nou->info=n;
- p->adr=nou;
- p=nou;
- }
- p->adr=NULL;
- }
- void afis()
- {
- nod *p=prim;
- while (p)
- {
- if((nrprim(p->info))==1)
- {g<<p->info<<" ";
- p=p->adr;}
- }
- }
- int main()
- {
- creare();
- afis();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement