최소 항으로 분수 줄이기 분자와 분모 모두에 균등하게 나눌 수 있는 수는 1을 제외하고는 없음을 의미합니다.
예를 들어, 24/4는 분수이고 이 분수의 가장 낮은 항은 6이거나 12/16은 분수입니다. 가장 낮은 항은 3/4입니다.
이제 분수를 가장 낮은 항으로 줄이는 c 프로그램을 작성해 보겠습니다.
예시 1
#include<stdio.h>
int main(){
int x,y,mod,numerat,denomi,lessnumert,lessdenomi;
printf("enter the fraction by using / operator:");
scanf("%d/%d", &x,&y);
numerat=x;
denomi=y;
switch(y){
case 0:printf("no zero's in denominator\n");
break;
}
while(mod!=0){
mod= x % y;
x=y;
y=mod;
}
lessnumert= numerat/x;
lessdenomi=denomi/x;
printf("lowest representation of fraction:%d/%d\n",lessnumert,lessdenomi);
return 0;
} 출력
enter the fraction by using / operator:12/24 lowest representation of fraction:1/2
예시
//reduce the Fraction
#include <stdio.h>
int main() {
int num1, num2, GCD;
printf("Enter the value for num1 /num2:");
scanf("%d/%d", &num1, &num2);
if (num1 < num2){
GCD = num1;
} else {
GCD = num2;
}
if (num1 == 0 || num2 == 0){
printf("simplified fraction is %s\n", num1?"Infinity":"0");
}
while (GCD > 1) {
if (num1 % GCD == 0 && num2 % GCD == 0)
break;
GCD--;
}
printf("Final fraction %d/%d\n", num1 / GCD, num2 / GCD);
return 0;
} 출력
Enter the value for num1 /num2:28/32 Final fraction 7/8