#include "brueche.h"

unsigned int ggT(unsigned int a, unsigned int b);

void kuerzen(struct brueche *b)
{
   unsigned int teiler;
	if ( b->zaehler < 0)
     teiler = ggT(-b->zaehler, b->nenner);
   else
     teiler = ggT(b->zaehler, b->nenner);
   b->zaehler = b->zaehler /(int) teiler;
   b->nenner /= teiler;
}


struct brueche add(struct brueche b1, struct brueche b2)
{
	struct brueche erg = {0,1};
   erg.zaehler = b1.zaehler*b2.nenner + b2.zaehler*b1.nenner;
   erg.nenner = b1.nenner*b2.nenner;
   kuerzen(&erg);
   return erg;
}

struct brueche sub(struct brueche b1, struct brueche b2)
{
	b2.zaehler *= -1;
   return add(b1,b2);
}

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






