Pagini recente » Cod sursa (job #134540) | Cod sursa (job #1121009) | Cod sursa (job #2023461) | Sport | Cod sursa (job #23897)
Cod sursa(job #23897)
#include <stdio.h>
int main()
{long n,i,j,p=1; int b; float r,aux,k; FILE *f,*g;
f=fopen("fractii.in","r");
fscanf(f,"%ld",&n);
fclose(f);
f=fopen("fr.txt","w");
fprintf(f,"%f ",float(1)/float(1));
fclose(f);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i!=j) {b=1;
k=float(i)/float(j);
f=fopen("test.txt","w");
fprintf(f,"%f",k);
fclose(f);
f=fopen("test.txt","r");
fscanf(f,"%f",&r);
fclose(f);
f=fopen("fr.txt","r");
while(!feof(f)) {fscanf(f,"%f",&aux);
if(aux==r) {b=0; break;}
}
fclose(f);
if(b) {g=fopen("fr.txt","a+");
fprintf(g,"%f ",r); p++;
fclose(g); }
}
f=fopen("fractii.out","w");
fprintf(f,"%ld",p);
fclose(f);
return 0;
}