Advertisement
ebx

egipatski razlomci

ebx
Sep 3rd, 2012
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float modul(float x, float y) {
  5.     if (fmod(x,y) < 0) return (fmod(x,y) + floor(y));
  6.     return fmod(x,y);
  7. }
  8.  
  9. void egy(float x, float y) {
  10.     printf("1/%.f", ceil(y/x));
  11.     if (modul(-y,x) != 0.0) {
  12.         printf(" + ");
  13.         egy(modul(-y,x), y*ceil(y/x));
  14.     }
  15. }
  16.  
  17. int main()
  18. {
  19.     float x, y;
  20.     printf ("Unesite brojilac i imenilac razlomka: ");
  21.     scanf ("%f %f",&x, &y);
  22.     egy(x,y);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement