through my quest in c prog in VS code, I was required to implement a few simple functions, which I wanted to test. Below the code is attached, along with the error message I've been receiving. is there something I defined wrong in the code? or is the cause of this fault something else? thank you in advance!
#include <stdio.h>
float AbsVal(float a)
{
float result;
if (a-0==a)
result=a;
if (0-a==a)
result=(-a);
return result;
}
int gcd (int a, int b)
{
int result;
if (a==0 && b==0)
result=0;
if (a==0)
result= b;
if (b==0)
result = a;
if (a%2==0 && b%2==0)
result= 2*gcd(a/2,b/2);
if (a%2==0 && b%2!=0)
result= 2*gcd(a/2,b);
if (a%2!=0 && b%2==0)
result= 2*gcd(a,b/2);
if (a%2!=0 && b%2!=0)
result= gcd(AbsVal(a-b),b);
return result;
}
int main()
{
AbsVal(3);
AbsVal(-2);
AbsVal(-3.1231);
AbsVal(5.9876);
gcd(15,3);
gcd(60,73);
gcd(456, 234);
gcd(100,10);
return 0;
}
fault message, while trying to run the .exe file:
Segmentation fault (core dumped)
note that I already looked at similar topics, but couldn't find the direct answer for my issue