Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions functions.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
void print_hello();
int factorial(int n);
int gcd(int x,int y);
int gcd_rec(int x, int y);
19 changes: 19 additions & 0 deletions gcd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "functions.h"

int gcd(int x,int y){
int gcd;
for(int i=1; i <= x && i <= y; ++i)
{
// Checks if i is factor of both integers
if(x%i==0 && y%i==0)
gcd = i;
}
return gcd;
}

int gcd_rec(int x, int y) {
if (y != 0)
return gcd_rec(y, x % y);
else
return n1;
}
7 changes: 7 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ int main(){
if(ans==-1)printf("Invalid input, re-enter by again starting program. Status : %d",ans);
else printf("Factorial of %d is %d",n,ans);
// cout<<(ans == -1?"Invalid input, re-enter by again starting program":"Factorial of "+to_string(n)+" is "+to_string(ans));
int x,y;
x=56;
y=98;
int g = gcd(x,y);
cout<<"GCD of "<<x<<" and "<<y<<" is "<<gcd(x,y);

cout<<"GCD of "<<x<<" and "<<y<<" using recursive method is "<<gcd_rec(x,y);
return 0;
}