diff --git a/CODE in C/Mathematical/GCD_Of_n_numbers.cpp b/CODE in C/Mathematical/GCD_Of_n_numbers.cpp new file mode 100644 index 0000000..a161147 --- /dev/null +++ b/CODE in C/Mathematical/GCD_Of_n_numbers.cpp @@ -0,0 +1,36 @@ +//This is a program to find GCD of n numbers. + +#include +using namespace std; + +//Writing the code for calculating GCD of two numbers. +int hcf(int a, int b){ +if(a>b){ + if(b==0){return a;} + else{return hcf(b,a%b);} +}else{ + if(a==0){return b;} + else{return hcf(a,b%a);} +} +} + +int main() { +int n,i,x,g; +cout<<"GCD of how many numbers do you want to find ?\n"; +cin>>n; +vector a; +cout<<"Enter the numbers now:\n"; +//Taking in the values for calculating GCD. +for(i=0;i>x; + a.push_back(x); +} +//Calculating the GCD. +g = a[0]; +for(i=1;i