实验三 数组
2023.4.26
一、实验目的:
掌握数组定义、初始化和元素的访问;理解向函数传递数组的实质及数组的
缺陷;理解二维数组的操作;学会各种常用的排序算法。
二、实验内容:
1. 斐波那契数列的正向实现方式
#include <iostream>
using namespace std;
int main()
{
int s[30];
s[0] = 0;
s[1] = 1;
for(int i = 2; i < 30; i++)
{
s[i] = s[i-1] + s[i-2];
}
int n;
cout << "input n: ";
cin >> n;
if(n < 30 && n >= 0)
cout << s[n] << endl;
else
cout << "n >= 30" << endl;
return 0;
}
2.二维数组的应用: 求 Z = 3X + 2Y (0<=x<=10, 0<=y<=8)
#include <iostream>
using namespace std;
int main()
{
int z[11][9];
for(int x = 0; x <= 10; x++)