-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadd two fraction.cpp
More file actions
36 lines (32 loc) · 754 Bytes
/
add two fraction.cpp
File metadata and controls
36 lines (32 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
using namespace std;
void addFraction(int num1, int den1, int num2,
int den2);
int main()
{
int T;
cin>>T;
while(T--)
{
int a,b,c,d,resultNum,resultDen;
cin>>a>>b>>c>>d;
addFraction(a,b,c,d);
}
}
/*Please note that it's Function problem i.e.
you need to write your solution in the form of Function(s) only.
Driver Code to call/invoke your function is mentioned above.*/
/*You are required to complete this function*/
void addFraction(int num1, int den1, int num2,int den2)
{
int s,u,m,t;
s=(num1*den2+num2*den1);
u=(den1*den2);
m=s/u;
for(t=s<u?s:u;t>=1;t--)
{
if(s%t==0 && u%t==0)
break;
}
cout<<s/t<<"/"<<u/t<<endl;
}