Pagini recente » Cod sursa (job #368704) | Cod sursa (job #2161436) | Cod sursa (job #7689) | Cod sursa (job #3235448) | Cod sursa (job #23917)
Cod sursa(job #23917)
#include <stdio.h>
int cmmdc(long a,long b)
{if(a<2||b<2) return 1;
while(a!=b)
{if(a>b) a=a-b;
else b=b-a;}
return a;
}
int main()
{long n,i,j,p=1,cm,x,y,aux1,aux2; int b; FILE *f,*g;
f=fopen("fractii.in","r");
fscanf(f,"%ld",&n);
fclose(f);
f=fopen("fr.txt","w");
fprintf(f,"%d %d ",1,1);
fclose(f);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i!=j) {b=1;
cm=cmmdc(i,j);
x=i/cm; y=j/cm;
f=fopen("fr.txt","r");
while(!feof(f)) {fscanf(f,"%ld %ld",&aux1,&aux2);
if(aux1==x&&aux2==y) {b=0; break;}
}
fclose(f);
if(b) {g=fopen("fr.txt","a+");
fprintf(g,"%ld %ld ",x,y); p++;
fclose(g); }
}
f=fopen("fractii.out","w");
fprintf(f,"%ld",p);
fclose(f);
return 0;
}