在begin-end区域中定义一个int类型数组 scores,录入三个值,91,88,60,最后输出数组中的三个值,效果如图:
时间: 2023-05-31 09:19:16 浏览: 639
### 回答1:
在begin-end区域中定义一个int类型数组scores,录入三个值,91,88,60,最后输出数组中的三个值,效果如图:
begin
int scores[3] = {91, 88, 60};
for(int i=; i<3; i++){
print(scores[i]);
}
end
输出结果为:
91
88
60
### 回答2:
首先,在begin-end区域中定义一个int类型数组scores,即代码如下:
```pascal
program scores;
var
scores: array[1..3] of Integer; //定义数组
begin
scores[1] := 91; //录入三个值
scores[2] := 88;
scores[3] := 60;
writeln('数组中的三个值为:'); //输出数组中的三个值
writeln(scores[1]);
writeln(scores[2]);
writeln(scores[3]);
end.
```
代码中,我们使用var关键字定义一个int类型的数组scores,它有3个元素。在begin-end区域中,我们分别给数组中的元素赋值,即scores[1]为91,scores[2]为88,scores[3]为60。
最后,我们用writeln函数输出数组中的三个值,即scores[1],scores[2]和scores[3],并加上相应的提示信息。
运行程序后,会看到以下输出结果:
```
数组中的三个值为:
91
88
60
```
这就是我们要实现的效果,即输出数组中的三个值。
总之,在Pascal中,可以使用数组来表示一组相同类型的数据,通过指定数组的大小和索引(下标)来访问其中的元素,从而方便地进行数据的存储和处理。
### 回答3:
在begin-end区域中定义一个int类型数组scores,录入三个值,91,88,60,最后输出数组中的三个值,可以采用如下代码实现:
```
begin
int scores[3]; // 声明一个包含3个整数的数组
scores[0] = 91; // 将第1个元素赋值为91
scores[1] = 88; // 将第2个元素赋值为88
scores[2] = 60; // 将第3个元素赋值为60
writeln('成绩一:', scores[0]); // 输出第1个元素
writeln('成绩二:', scores[1]); // 输出第2个元素
writeln('成绩三:', scores[2]); // 输出第3个元素
end.
```
以上代码将开始执行(begin),定义了一个包含3个整数的数组scores。接着,将数值91赋值给scores的第一个元素(即索引值为0的元素),88赋值给第二个元素(索引值为1),60赋值给第三个元素(索引值为2)。
最后,将数组中的三个元素输出到屏幕上,通过writeln语句输出。注意:index的范围是0-2,而不是1-3,这是因为在Pascal中,数组的第一个元素从0开始。
最终的运行结果是:
```
成绩一:91
成绩二:88
成绩三:60
```
以上就是在begin-end区域中定义一个int类型数组scores,录入三个值,91,88,60,最后输出数组中的三个值的方法。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)