Cod sursa(job #1244004)

Utilizator BanhidiBanhidi Zoltan Banhidi Data 16 octombrie 2014 17:50:08
Problema Fractii Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <stdio.h>
 
struct tort {
       int p,q;
};

int lnko(int a, int b) {
    while (a!=b) 
          if (a>b)
             a=a-b;
             else b=b-a;
    return a;
    }

bool keres(struct tort e, struct tort g[], int h) {
   int i; bool ok=false;
   for (i=0; i<h; ++i)
       if ((e.p=g[i].p) && (e.q=g[i].q))
          ok=true;
   return ok;
   } 


int main() {
    struct tort t[1000],z;
    int n,i,j,k,r=0,u;
    FILE *f;
    f=fopen("fractii.in","r");
    fscanf(f,"%d",&n);
    fclose(f);
    for (i=1; i<=n; i++) {
        z.p=i;
    	for (j=1; j<=n; j++) {
    	    z.q=j; 
    	    u=lnko(z.p,z.q);
    	    z.p=z.p/u; z.q=z.q/u;
    	    if ((keres(z,t,r)==false) || (r==0)) {
    	       r++;
    	       t[r-1]=z;
    	       }
    	    }
    	 }
    f=fopen("fractii.out","w");
    fprintf(f,"%d",r);
    fclose(f);
    }