Advertisement

What is a way to simplify fractions without using a pre-made function.

Started by January 10, 2003 08:29 PM
0 comments, last by dampe64 21 years, 10 months ago
Is their any way to write a program to do this. What is the formula to simplify them using no logic.
sorry im a noob dont know if there are any library functions to do that, the best i could come up is this...


  #include <iostream>using namespace std;int CommonDiv(int,int);void Simplify(int &,int &);int main(){	int a;	int b;	cin >> a;	cout << "---\n";	cin >> b;	Simplify(a,b); 	cout << "\n\n" << a << "\n---\n" << b << "\n\n";		return 0;}int CommonDiv(int a, int b){	if (b == 0)		return a;		return CommonDiv(b, a % b);}void Simplify(int &a, int &b){	if (a==0 && b==0)	{}	else	{		int c;		c = CommonDiv(a,b);		a = a/c;		b = b/c;	}}  

This topic is closed to new replies.

Advertisement