C++动态数组的实现
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n) 7 { 8 int *p=new int[n+1]; 9 p[0]=0; 10 p[1]=1; 11 for(int i=2;i<=n;i++) 12 { 13 p[i]=p[i-1]+p[i-2]; 14 } 15 cout<<p[n]<<endl; 16 } 17 return 0; 18 }
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n) 7 { 8 int *p=new int[n+1]; 9 p[0]=0; 10 p[1]=1; 11 for(int i=2;i<=n;i++) 12 { 13 p[i]=p[i-1]+p[i-2]; 14 } 15 cout<<p[n]<<endl; 16 } 17 return 0; 18 }