|
|
back to boardaccess violation it has all right answer and why access violation? #include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> int a[40][50]; using namespace std; int main(){ int n,i,j,k; cin>>n; a[0][0]=2; a[1][0]=2; if (n>1){ for (i=2; i<n; i++){ for (j=0; j<39; j++){ a[i][j]=a[i-1][j]+a[i-2][j]; } for (j=0; j<19; j++){ a[i][j+1]+=a[i][j]/10; a[i][j]=a[i][j]%10; } } } for (i=39; i>-1; i--){ if (a[n-1][i]>0){ for (j=i; j>-1; j--){ cout<<a[n-1][j]; } break; } } //system("pause"); } |
|
|