reduction of rational numbers

hi thr, i just saw dis request in some post. d user needed tyhe code to reduce rational num eg 10/15 into 2/3
so here is d code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void reducing(int n, int d)
{
     int arr[10],max,p,q,i;
     if(n>d) max = n;
     else max=d;
     p=n;
     q=d;
     for(i=2;i<=max/2;i++)
     {
	  if(n%i ==0 && d%i ==0)
	  {
		n/=i;
		d/=i;
		}
	  }
     printf("the reduced form of %d/%d = %d/%d",p,q,n,d);
}

the above code is in c language. the user is requested to convert the i/o stmt in c++. sumhow i was having problem wid c++ header files
1
2
3
4
5
6
7
8

#include <iostream>

using namespace std;


//Instead of printf
cout<<"The reduced form of"<<p<<"/"<<q<<"="<<n<<"/"<<d<<endl;
Last edited on
Topic archived. No new replies allowed.