ubuntu@ubuntu:~/daa$ make t4
g++ t4.cpp -o t4
t4.cpp: In function ‘int caminos(int)’:
t4.cpp:11: error: expected type-specifier before ‘arr’
t4.cpp:11: error: expected ‘,’ or ‘;’ before ‘arr’
make: *** [t4] Error 1
Código C++:
Ver original
#include <iostream> using namespace std; int caminos(int n) { if (n >=1 && n<= 3) { return n; } else if(n>3){ int *arr = new arr[n+1]; arr[0] = 0; arr[1] = 1; arr[2] = 2; arr[3] = 3; for (int i = 4; i < n+1; i++) { arr[i] = arr[i-1] + arr[i-2]; } return arr[n]; } } int main (int argc, char* argv[]) { int a; cin>>a; while(a != 0) { caminos(a); cin >> a; } return 0; }