Jump to content

Sequencia Fibbonacci


darkeyes

Recommended Posts

pessoal com este codigo o que me falta ou que esta errado para obter a sequencia de fibonacci?

#include <stdio.h>

main ()

{

int i, n=0;
long long int fn1, fn2, x;
int fib(int);

printf("\tSequência de Fibonacci\n");
printf("\nIntroduza o um número natural: \n");
scanf(" %d", &n);

for (i=0 ; i==n ; i=0)
{
printf("O Soma=%d", i);
}
for (i=1 ; i==n ; i=1)
{
printf("1 Soma=%d\n", i);
}
for (fib=int fib(int n) ,fn1=fib(n-1), fn2=fib(n-2) ; i>=2 && i<=25; i=fn1+fn2);
{
printf("0 Soma=%d\n", i);
}
}
Link to comment
Share on other sites

Primeiro de tudo:

O que é isto?

int fib(int);

Aos anos que programo C nunca vi nada assim, mas pode ser algo que desconheça.

Um casting ao fib para inteiro? :o

Provavelmente queres alocar "int fib[N];"

Depois, os teus dois primeiros fors deviam ser convertidos num if.

if (n==0 || n==1)

  printf("%d Soma: %d\n",n,n);

Ou em dois, mas nunca usar um for para o fazer.

O for seguinte não percebo nada, a começar pela inicialização, "fib=int fib(int n)".

Isto nem sequer compila, dá logo erro.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.