Pagini recente » Cod sursa (job #2349995) | Cod sursa (job #2832329) | Cod sursa (job #121802) | Cod sursa (job #2376523) | Cod sursa (job #109236)
Cod sursa(job #109236)
#include<iostream.h>
#include<fstream.h>
struct nod{
long inf;
nod *leg;};
void adauga_inc(nod *&cap,long x)
{nod *p;
p=new nod;
p->inf=x;
p->leg=cap;
cap=p;}
void adauga_sf(nod *&cap,long x)
{nod *p,*q;
if(!cap) adauga_inc(cap,x);
else {for(p=cap;p->leg!=NULL;p=p->leg);
q=new nod;
q->inf=x;
q->leg=NULL;
p->leg=q;}
}
int prime(int x,int y)
{while(x!=y)
{if(x>y) x=x-y;
else y=y-x;}
return x;}
void main()
{long n,i,x,y;nod *cap=NULL,*p,*q;
ifstream f("C:\\oij\\pairs.in");
ofstream g("C:\\oij\\pairs.out");
f>>n;
for(i=0;i<n;i++)
{f>>x;adauga_sf(cap,x);}
for(p=cap;p->leg!=NULL;p=p->leg)
{x=p->inf;
for(q=p->leg;q!=NULL;q=q->leg)
{y=q->inf;
if(x!=y&&prime(x,y)==1) g<<"("<<x<<","<<y<<");";
}
}
}