From f7be155d6657f9a46e1d778dfb73e63f70dab4fb Mon Sep 17 00:00:00 2001 From: Udhay <72250606+Udhay-Brahmi@users.noreply.github.com> Date: Sat, 26 Dec 2020 08:09:46 +0530 Subject: [PATCH] Create Add two fractions --- Add two fractions | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Add two fractions diff --git a/Add two fractions b/Add two fractions new file mode 100644 index 0000000..7a55936 --- /dev/null +++ b/Add two fractions @@ -0,0 +1,37 @@ +// { Driver Code Starts +#include +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); + + } +} +// } Driver Code Ends + + +/*You are required to complete this function*/ +void addFraction(int num1, int den1, int num2,int den2) +{ +//Your code here +long long int a = (num1*den2 + num2*den1); +long long int y = (den1*den2); +long long int k =y; +for(long long int i=k;i>=1;i--){ + if(a%i==0 and y%i==0){ + a=a/i;y=y/i; + } +} +cout<