From 5bb16314a333e858389fbc08bd4328d5b992a226 Mon Sep 17 00:00:00 2001 From: akshay Date: Sat, 10 Oct 2020 19:48:55 +0530 Subject: [PATCH] Program to calculate GCD of n numbers. --- CODE in C/Mathematical/GCD_Of_n_numbers.cpp | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 CODE in C/Mathematical/GCD_Of_n_numbers.cpp 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