08/03/13 21:20:13
俺の半分は優しさで出来ています
#include<stdio.h>
typedef struct bunsu{
int bunshi;
int bunbo;
} BUNSU;
int getgcd(int m, int n){
while(m*n){ if(m>n) m%=n; else n%=m; }
return m+n;
}
void yakubun_p(BUNSU *x){
int gcd;
gcd = getgcd(x->bunshi, x->bunbo);
x->bunshi /= gcd;
x->bunbo /= gcd;
}
int main(void){
BUNSU a;
printf("分子?"); scanf("%d", &a.bunshi);
printf("分母?"); scanf("%d", &a.bunbo);
printf("%d / %d = ", a.bunshi, a.bunbo);
yakubun_p(&a);
printf("%d / %d\n", a.bunshi, a.bunbo);
return 0;
}