/*I have coded this but it is not working fine it kept saying "Segmentation fault" and i can't track it down, can someone help me on this i want it badly!*/
#include<iostream>
using namespace std;
int k=0;
void gcd(int a, int b);
void gcd(int a, int b)
{
static int temp=b;
int buffer[20],buffer1[20],j,i;
for(i=0; i<temp; i++)
{
if(b>0&&temp%b==0)
{
buffer[k]=b;
k++;
gcd(a,b-1);
}
else
gcd(a,b-1);
}
for(i=0; i<temp; i++)
{
if(a%buffer[i]==0)
buffer1[i]=buffer[i];
}
int GCD = buffer1[0];
for(i=0; i<temp; i++)
{
if(buffer1[i]>GCD)
GCD=buffer1[i];
}
cout<<"This is just the gcd"<<GCD;
}
int main()
{
int num,num2;
cout<<"Enter the first number\n";
cin>>num;
cout<<"Enter the second number\n";
cin>>num2;
gcd(num,num2);
return 0;
}
book_worm
0
Newbie Poster
Recommended Answers
Jump to PostUsually when I work on a function I make it in main so If I get a error like a seg fault I take out bit and peices or rebuild the function test each small part and compile and run no error build on and repeat so I can narrow …
All 2 Replies
power_computer
20
Junior Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.