#include<stdio.h> void show_arr(int row,int col,int arr[][col]) { for(int i=0; i<row; i++) { for(int j=0; j<col; j++) { printf("%d ",arr[i][j]); } printf("\n"); } } int main(int argc,const char* argv[]) { int arr[2][5] = { {1,2,3,4,5}, {2,3,4,5,6} }; show_arr(2,5,arr); return 0; }
时间: 2024-04-17 08:23:46 浏览: 11
这段代码是一个简单的C语言程序。它定义了一个名为show_arr的函数,用于打印一个二维数组的元素。然后在main函数中创建了一个2行5列的二维数组arr,并将其初始化为一些整数值。最后调用show_arr函数来打印数组的内容。运行该程序将输出数组的元素。
这段代码的输出结果为:
1 2 3 4 5
2 3 4 5 6
相关问题
} 2、程序填空 #include<stdio.h> voidfun(inta[],intn) {inti,t;
#include <stdio.h>
void fun(int a[], int n) {
int i, t;
for (i = 0; i < n / 2; i++) {
t = a[i];
a[i] = a[n - 1 - i];
a[n - 1 - i] = t;
}
}
// 示例测试
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int i;
fun(arr, 5);
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
#include<stdio.h> #include<string.h> struct student{ char name[100]; int age; }; int main(void) { int i,j; struct student arr[5]; for(i=0;i<5;i++) { scanf("%s%d",arr[i].name,&arr[i].age); } for(i=0;i<4;i++) {
在代码中,最后一个for循环没有结束,缺少右括号。下面是修改后的代码:
```
#include<stdio.h>
#include<string.h>
struct student{
char name[100];
int age;
};
int main(void) {
int i,j;
struct student arr[5];
for(i=0;i<5;i++) {
scanf("%s%d",arr[i].name,&arr[i].age);
}
for(i=0;i<4;i++) {
for(j=0;j<4-i;j++) {
if(arr[j].age>arr[j+1].age) {
struct student t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
for(i=0;i<5;i++) {
printf("%s %d\n",arr[i].name,arr[i].age);
}
return 0; //需要加上返回值
} //需要加上右括号
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.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)
![](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)