Question
C Programming Language Problem is to create a program that will find the greatest GCD in an array of numbers. I can get the correct
C Programming Language
Problem is to create a program that will find the greatest GCD in an array of numbers. I can get the correct answers but my problem is efficiency and the checking software marks my answer wrong with the reason: TIMELIMIT. Code attempted is given below.
#include
int gcd(int n1, int n2) { int i, gcd; for(i=1; i
int findGGCD(int arr[], int n) { int i, j; int ggcd = 0; for (i = 0; i arr[j+1] && arr[j+1]!=0) { k = gcd(arr[j+1], arr[i] % arr[j+1]); } else if(arr[i] > arr[j+1] && arr[j+1]==0) { k = arr[i]; } else { k = gcd(arr[i], arr[j+1]); } if(k > ggcd) { ggcd = k; } } } return ggcd; }
int main() { int cases; scanf("%d", &cases); if(cases100) { return 1; } for(int q = 1; q100) { return 1; } int ggcd; int arr[n]; for(int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started