问题:
输入一个分数,将该分数分解为埃及分数。
真分数:分子小于分母的分数
埃及分数:分子为一的分数
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { long int a, b, c; scanf("%d%d", &a, &b); while(1) { if(b%a) c = b/a+1; else { c = b/a; a=1; } if(a==1) { printf("1/%ld\n", c); break; } else printf("1/%ld\n", c); a=a*c-b; b=b*c; if(a==3&&b%2==0) { printf("1/%ld+1/%ld\n", b/2,b); break; } } return 0; } /* 132 155 1/2 1/3 1/55 1/10230 */
原文地址:http://blog.csdn.net/orangeisnotapple/article/details/44787821