chharlie Posted October 13, 2009 at 12:04 AM Report Share #291455 Posted October 13, 2009 at 12:04 AM A minha duvida tem mais a ver do porque de esta funçao nao estar a funcionar neste programazito #include <stdio.h> #include <math.h> float val(float x,int n,float t){ int i; float val=0.0; for(i=1;i<=n;i++) val+=x/(pow((1+t),(float) i)); return val; } int main(){ float x,t; int n; printf("Introduza a taxa em vigor: "); scanf("%f",&t); printf("Introduza o numero de anos: "); scanf("%d",&n); printf("Introduza o valor de x: "); scanf("%f",&x); printf("O VAL = %f\n",val(x,n,t)); return 1; } ja tentei vendo as bibliotecas de C e as referencias para a linguagem alterar pow para powf visto estar a trabalhar com doubles e mesmo assim nada o erro e este: /tmp/ccg0UAOK.o: In function `val': prog5.c:(.text+0x37): undefined reference to `pow' collect2: ld returned 1 exit status outro erro é, pelo que eu li posso fazer a declaraçao e inicializaçao das variaveis dentro de um ciclo for, porem sempre que faço isso da-me este erro: prog0408.c: In function ‘main’: prog0408.c:7: error: ‘for’ loop initial declaration used outside C99 mode prog0408.c:8: error: ‘for’ loop initial declaration used outside C99 mode um exemplo de programa onde me da este erro #include <stdio.h> int main(){ //int a,b; for(int a=1;a<=5;a++){ for(int b=1;b<=10;b++) printf("%2d x %2d = %2d\n",a,b,a*b); printf("Pressione a tecla ENTER"); getchar(); } return 1; } eu sei que sao duvidas muito futeis mas gostava que alguem mas esclarece-se. obrigado Link to comment Share on other sites More sharing options...
Triton Posted October 13, 2009 at 12:21 AM Report Share #291457 Posted October 13, 2009 at 12:21 AM Compila da seguinte forma: gcc -std=C99 programa.c -o programa <3 life Link to comment Share on other sites More sharing options...
Baderous Posted October 13, 2009 at 08:27 PM Report Share #291577 Posted October 13, 2009 at 08:27 PM Para o pow tens de linkar com a biblioteca do math. Usa a flag -lm na compilação. Link to comment Share on other sites More sharing options...
chharlie Posted October 25, 2009 at 05:46 PM Author Report Share #293309 Posted October 25, 2009 at 05:46 PM problema resolvido. apesar de achar estupido no gcc ter que linkar a biblioteca math.h e nao ter que linkar outras como stdio.h ou stdlib.h mesmo assim obrigado pelo esclarecimento Link to comment Share on other sites More sharing options...
Baderous Posted October 25, 2009 at 05:52 PM Report Share #293310 Posted October 25, 2009 at 05:52 PM The compiler automatically links against libc (the C library) so thatyou don't have to specify "-lc" every time. The math functions are in libm though, and since the compiler doesn't link against it automatically, you need "-lm". http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/53e04251bfee701d Link to comment Share on other sites More sharing options...
Rui Carlos Posted October 29, 2009 at 07:08 PM Report Share #293901 Posted October 29, 2009 at 07:08 PM Eu nunca tive de meter o -lm. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now