This is my code ... I fixed it .. so now it has no errors (even though i still dont have the factors i wanted,... but thats a nother think i will think later.)
Code:
#include<stdio.h>
#include<math.h>
#include<malloc.h>
typedef struct euclid{
int m;
int a;
int b;
}Euclid;
Euclid ext_gcd(int m, int n){
Euclid euclidp, euclidp2;
if(n==0) {
euclidp.m=m;
euclidp.a=1;
euclidp.b=0;
printf("ext_gcd(%d,%d)=%d=%d*%d+%d*%d\n",m,n,euclidp.m,m,euclidp.a,n,euclidp.b);
return euclidp;
}
// euclidp2=(struct euclid *)malloc(sizeof(struct euclid));
euclidp2=ext_gcd(n, m%n);
euclidp2.m=euclidp.m;
euclidp2.a=euclidp.b;
euclidp2.b=(euclidp.a)-floor(m/n)*(euclidp.b);
printf("ext_gcd(%d,%d)=%d=%d*%d+%d*%d\n",m,euclidp2.m,m,euclidp2.a,n,euclidp2.b);
return euclidp2;
}
int main(){
printf("Euclid Algorithm (Extended)\n");
ext_gcd(954,288);
return 0;
}
I realized that it is not necesary pointers... so i did it with out them.
and i got :
Code:
[l05013@oli001 ~/tuesday4_2]$ ./a.out
Euclid Algorithm (Extended)
ext_gcd(18,0)=18=18*1+0*0
ext_gcd(90,1074095270)=90=1074037868*18+-2147483648*1073827124
ext_gcd(288,0)=288=0*90+0*134513212
ext_gcd(954,-1073743448)=954=1075289408*288+-2147483648*0
[l05013@oli001 ~/tuesday4_2]$ emacs 1206_2_03.c
wich is at least something... (no compiling errors)
but What i want to ask you.
is what if i want to do it with pointers?
Code:
#include<stdio.h>
#include<math.h>
#include<malloc.h>
typedef struct euclid{
int m;
int a;
int b;
}Euclid;
Euclid * ext_gcd(int m, int n){
Euclid *euclidp, *euclidp2;
if(n==0) {
euclidp->m=m;
euclidp->a=1;
euclidp->b=0;
printf("ext_gcd(%d,%d)=%d=%d*%d+%d*%d\n",m,n,euclidp->m,m,euclidp->a,n,euclidp->b);
return euclidp;
}
// euclidp2=(struct euclid *)malloc(sizeof(struct euclid));
euclidp2=ext_gcd(n, m%n);
euclidp2->m=euclidp->m;
euclidp2->a=euclidp->b;
euclidp2->b=(euclidp->a)-floor(m/n)*(euclidp->b);
printf("ext_gcd(%d,%d)=%d=%d*%d+%d*%d\n",m,euclidp2->m,m,euclidp2->a,n,euclidp2->b);
return euclidp2;
}
int main(){
printf("Euclid Algorithm (Extended)\n");
ext_gcd(954,288);
return 0;
}
it would be something like this but and i can compile it in my Mac(Unix terminal on Mac), but when executing it.. is says Segmentation Fault!
i run the debugger and as far as I understood... is said to me that is trying to access a part of the memory which i dont't have permission.
(Further more.. my kernel has that proteccion.)
in windows..(Unix terminal on Windows) well it doesn not compile.
it says...
[l05013@oli001 ~/tuesday4_2]$ gcc 1206_2.c -lm
/usr/lib/gcc-lib/i386-vine-linux/3.3.2/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld ended in status 1
[l05013@oli001 ~/tuesday4_2]$
what does it mean?? and how can i get this program well compiled?