Advertisement
Guest User

kek

a guest
Nov 22nd, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main(void) {
  5.   int a = 0;
  6.   int b = 0;
  7.   int x = 1000;
  8.  
  9.   printf("This program simplifies small fraction.\n");
  10.   printf("\nFormat (a/b) Enter a: ");
  11.   scanf("%d", &a);
  12.   printf("\nFormat (a/b) Enter b: ");
  13.   scanf("%d", &b);
  14.  
  15.   while ( x > 1 ) {
  16.     if ( a % x == 0 && b % x == 0 ) {
  17.       a = a/x;
  18.       b = b/x;
  19.     }
  20.     x--;
  21.   }
  22.  
  23.   if ( a == b ) {
  24.     printf("\n%d\n", a);
  25.     return 0;
  26.   }
  27.   if ( a > b && a % b != 0 ) {
  28.     printf("\n%d %d/%d\n", a / b, a % b, b);
  29.     return 0;
  30.   }
  31.   if ( b == 1 ) {
  32.     printf("\n%d\n", a);
  33.     return 0;
  34.   }
  35.   if ( a > b && a % b == 0 ) {
  36.     printf("\n%d", a % b);
  37.     return 0;
  38.   }
  39.   printf("\n%d/%d\n", a, b);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement