Skip to content

Create Add two fractions #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Add two fractions
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// { Driver Code Starts
#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);

}
}
// } 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<<a<<"/"<<y<<endl;
}