Having some errors, learning c (Euclidean Algorithm) -
so have done programming in python before, , trying hands out old solutions/methods used there. having syntax/compiler errors , feel im missing something. dumb here code.
//euclidian algorithm in c //a=bq+r gcd(a,b)=gcd(b,r) //recursive solution //devin martin #define _crt_secure_no_warnings // avoid scanf warning or error #include <stdio.h> int main() { int a, b = 0; int gcd(a, b); { if (b == 0); return a; return gcd(b, % b); //a%b = r } }
errors severity code description project file line
error lnk2019 unresolved external symbol _gcd referenced in function _main euclidianalgorithm d:\documents\visual studio 2015\projects\euclidianalgorithm\euclidianalg.obj 1
warning c4700 uninitialized local variable 'a' used euclidianalgorithm d:\documents\visual studio 2015\projects\euclidianalgorithm\euclidianalg.c 14
error lnk1120 1 unresolved externals euclidianalgorithm d:\documents\visual studio 2015\projects\euclidianalgorithm\debug\euclidianalgorithm.exe 1
you can't define function inside of function in c. also, function definition incorrect, need declare type of parameters inside of parameter list.
#include <stdio.h> int gcd(int a, int b) { if (b == 0) return a; return gcd(b, % b); //a%b = r } int main() { printf("gcd(15,6)=%d\n",gcd(15,6)); }
Comments
Post a Comment