main() { int hasil; hasil = fpb(150, 35); printf("FPB dari 150 dan 35 adalah %d\n", hasil); hasil = fpb(1026, 405); printf("FPB dari 1026 dan 405 adalah %d\n", hasil); hasil = fpb(83, 240); printf("FPB dari 83 dan 240 adalah %d\n",hasil); }
int main() { pecahan_t x, y, z; scanf("(+ %d/%u %d/%u)", &x.pembilang, &x.penyebut, &y.pembilang, &y.penyebut); // rumusnya kalikan silang // 7/3 + 1/6 // pembilang = 7*6 + 1*3 // penyebut = 7*6 // penambahan z.pembilang = x.pembilang*y.penyebut + x.penyebut*y.pembilang; z.penyebut = x.penyebut*y.penyebut; // sederhanakan int fpbz = fpb(abs(z.pembilang), z.penyebut); z.pembilang /= fpbz; z.penyebut /= fpbz; printf("%d", z.pembilang); if (z.penyebut != 1) printf("/%u\n", z.penyebut); return 0; }
int main() { typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_corefinement<Polyhedron> Corefinement; std::stringstream fpa(cube_a); std::stringstream fpb(cube_b); Polyhedron pa; Polyhedron pb; fpa >> pa; fpb >> pb; assert( pa.size_of_vertices() == 8); assert( pb.size_of_vertices() == 8); { Corefinement coref; std::list<std::vector<Kernel::Point_3> > polylines; std::vector<std::pair<Polyhedron*, int> > result; coref( pa, pb, std::back_inserter(polylines), std::back_inserter(result), Corefinement::Intersection_tag ); assert( polylines.size() == 1 ); assert( polylines.begin()->size() == 1 ); assert( result.size() == 0 ); } pb.clear(); std::stringstream fpc(inside_a); fpc >> pb; assert( pb.size_of_vertices() == 4); { Corefinement coref; std::list<std::vector<Kernel::Point_3> > polylines; std::vector<std::pair<Polyhedron*, int> > result; coref( pa, pb, std::back_inserter(polylines), std::back_inserter(result), Corefinement::Intersection_tag ); assert( polylines.size() == 4 ); assert( polylines.begin()->size() == 1 ); assert( result.size() == 1 ); assert( result[0].first->size_of_vertices() == 4); } }
int fpb(int a, int b) { if (b == 0) return a; else return fpb(b, a%b); }