История изменений
Исправление frozenix, (текущая версия) :
хотя не в этом проблема
#include <stdio.h>
#include <stdlib.h>
long pow(double a, double b)
{
printf("DEBUG: a = %f, b = %f\n", a, b);
if(b <= 0) return 1;
if(b == 1) return a;
return a * pow(a, b - 1);
}
int main(int argc, char *argv[])
{
printf("%ld", pow(3, 2));
}
andrew@andrew-desktop ~ $ gcc test.c -o test
test.c:5:6: warning: conflicting types for built-in function ‘pow’ [enabled by default]
andrew@andrew-desktop ~ $ ./test
DEBUG: a = 3.000000, b = 2.000000
DEBUG: a = 3.000000, b = 1.000000
9
#include <stdio.h>
#include <stdlib.h>
double pow(double a, double b)
{
printf("DEBUG: a = %f, b = %f\n", a, b);
if(b < 0) return 1;
return a * pow(a, b - 1);
}
int main(int argc, char *argv[])
{
printf("%f", pow(3, 2));
}
andrew@andrew-desktop ~ $ gcc test.c -o test
andrew@andrew-desktop ~ $ ./test
9.000000
Исходная версия frozenix, :
хотя не в этом проблема
#include <stdio.h>
#include <stdlib.h>
long pow(double a, double b)
{
printf("DEBUG: a = %f, b = %f\n", a, b);
if(b < 0) return 1;
return a * pow(a, b - 1);
}
int main(int argc, char *argv[])
{
printf("%ld", pow(3, 2));
}
andrew@andrew-desktop ~ $ gcc test.c -o test
test.c:5:6: warning: conflicting types for built-in function ‘pow’ [enabled by default]
andrew@andrew-desktop ~ $ ./test
DEBUG: a = 3.000000, b = 2.000000
DEBUG: a = 3.000000, b = 1.000000
DEBUG: a = 3.000000, b = 0.000000
DEBUG: a = 3.000000, b = -1.000000
27
#include <stdio.h>
#include <stdlib.h>
double pow(double a, double b)
{
printf("DEBUG: a = %f, b = %f\n", a, b);
if(b < 0) return 1;
return a * pow(a, b - 1);
}
int main(int argc, char *argv[])
{
printf("%f", pow(3, 2));
}
andrew@andrew-desktop ~ $ gcc test.c -o test
andrew@andrew-desktop ~ $ ./test
9.000000