【DidaOJ】[492]【C Language Training】List the Simplest Proper Fraction Sequence

Problem Description

Loading...

Problem Analysis

Algorithm for finding the greatest common divisor

cpp
1
2
3
4
5
6
int gcd(int a,int b) {
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}

When the greatest common divisor of the numerator and denominator is 1
this fraction is in lowest terms
just output as required

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<stdio.h>
int gcd(int a,int b) {
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main() {
	for(int i=1; i<40; i++) {
		if(gcd(40,i)==1)
			printf("%d/40,",i);
	}
	return 0;
}

Problem link: 【DidaOJ】[492]【C Language Training】List the Sequence of Simplest Proper Fractions

Loading...