程序的执行结果是: #define N 15 void fun(int b[],int nint m){int i,j; for(i=m;i>=n;i--) b[i+1]=b[i]; int main() { int i,a[N]={1,2,3,4,5,6,7,8,9,10}; fun(a,1,9); for(i=0;i<5;i++)printf("%d ",a[i]); return 0;
时间: 2024-04-21 17:29:15 浏览: 17
这段程序有语法错误,编译无法通过。首先,在函数 `fun` 的参数列表中,缺少了一个逗号,应该是 `void fun(int b[], int n, int m)`。其次,在函数 `main` 中,调用了函数 `fun` 的时候,参数应该传入三个,而不是两个,应该是 `fun(a, 1, 9)`。最后,在函数 `main` 中,将数组 `a` 的前 5 个元素输出的语句也存在错误,应该是 `for(i=0;i<5;i++) printf("%d ",a[i]);`。纠正完以上错误后,程序的执行结果是:2 3 4 5 6。
相关问题
完成以下C语言代码功能:将主函数中输入的字符串反序存放。#include<stdio. h> #include<conio. h> #include(string. h> #define N 50 void fun(char *str, int n)
我可以提供一个示例代码:#include <stdio.h>
#include <string.h>int main ()
{
char str[100], temp;
int i, j; printf("输入一个字符串: ");
gets(str); j = strlen(str) - 1; for (i = 0; i < j; i++, j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
} printf("反序后的字符串: %s", str); return 0;
}
#include <stdio.h> #define N 20 void fun(int a[],int n,int m) { int i ; for(i=m;i>=n;i--) { a[i+1]=a[i]; } int main() { int i,a[N]={1,2,3,4,5,6,7,8,9,10}; fun(a,2,9); for(i=0;i<5;i++) { printf("%d",a[i]); } return 0;}
这段代码存在语法错误,缺少一个右括号。同时,在调用 `printf` 函数时,应该使用换行符 `\n` 来换行。下面是修改后的代码:
```
#include <stdio.h>
#define N 20
void fun(int a[], int n, int m) {
int i;
for (i = m; i >= n; i--) {
a[i + 1] = a[i];
}
}
int main() {
int i, a[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fun(a, 2, 9);
for (i = 0; i < 10; i++) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
```
运行结果为:`1 2 10 9 8 7 6 5 4 3`。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)