Title:
We know that fractions consist of numerator and denominator, so given you two integers (negative, can be positive), the first one represents the numerator, the second represents the denominator. Can you turn them into the simplest form?
For example: Input:-4 8; output: -1/2
voidMain () {intb;intI=1;intFlag=i;//Greatest Common DivisorintFlag2=0;//the number of negative signs in a, bscanf"%d%d",&a,&b);if(b = =0){return;}//the denominator cannot be 0if(A = =0){//The molecule is 0 o'clock, and the result is 0.printf"%d/%d =%d\n", A, B,0); return ;}if(a<0) {Flag2++; A= -A;}if(b<0) {Flag2++; b= -b;} while(I <= (a>b?)b:a)) {if(a%i==0&& b%i==0) {flag= i;//find the number that can be divisible by a, b } ++i;} printf ("Greatest Common divisor is:%d\n", flag);if(Flag2 = =1) {printf ("-%d/%d\n", a/flag,b/flag);}Else{printf ("%d/%d\n", a/flag,b/flag);}}
The simplification of fractions