All pastes #487452 Raw Edit

David

public cpp v1 · immutable
·published 2007-05-14 13:54 UTC
rendered paste body
#include <iostream>using namespace std;/* ESTE ES EL EJERCICIO RACI1, QUE HA PASADO EL JUEGO DE PRUEBAS */struct Racional {    int num, den;};// Funcio que calcula el MCD de dos nombresint mcd(int x, int y) {    if (y == 0) return x;    return mcd(y, x%y);}// Funcio que retorna un racional normalitzatRacional racional(int n, int d) {    Racional res;    res.num = n/mcd(n,d);    res.den = d/mcd(n,d);    if (res.den < 0) {        res.num = -res.num;        res.den = -res.den;    }    return res;}/* ESTE ES EL NUEVO, APROVECHANDO EL ANTERIOR PARA NORMALIZAR LOS RACIONALES */// Accio que llegeix un racionalvoid llegeix_racional(Racional& r, bool& final) {    int x, y;    if (cin >> x >> y) r = racional(x,y);    else final = true;}// Accio que escriu un racionalvoid escriu_racional(const Racional& r) {    cout << r.num;    if (r.den != 1) cout << "/" << r.den;}