Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void) {
- int a = 0;
- int b = 0;
- int x = 1000;
- printf("This program simplifies small fraction.\n");
- printf("\nFormat (a/b) Enter a: ");
- scanf("%d", &a);
- printf("\nFormat (a/b) Enter b: ");
- scanf("%d", &b);
- while ( x > 1 ) {
- if ( a % x == 0 && b % x == 0 ) {
- a = a/x;
- b = b/x;
- }
- x--;
- }
- if ( a == b ) {
- printf("\n%d\n", a);
- return 0;
- }
- if ( a > b && a % b != 0 ) {
- printf("\n%d %d/%d\n", a / b, a % b, b);
- return 0;
- }
- if ( b == 1 ) {
- printf("\n%d\n", a);
- return 0;
- }
- if ( a > b && a % b == 0 ) {
- printf("\n%d", a % b);
- return 0;
- }
- printf("\n%d/%d\n", a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement