#include <stdio.h> /************found************/ int fun (n) { int c; /************found************/ if(n=1) c = 10 ; else c= fun(n-1)+2; return(c); } main() { int n; printf("Enter n : "); scanf("%d",&n); printf("The result : %d\n\n", fun(n)); }程序改错,用C语言
时间: 2023-07-01 17:23:51 浏览: 41
修改后的程序如下:
```c
#include <stdio.h>
int fun(int n)
{
int c;
if(n == 1)
c = 10;
else
c = fun(n-1) + 2;
return c;
}
int main()
{
int n;
printf("Enter n: ");
scanf("%d", &n);
printf("The result: %d\n", fun(n));
return 0;
}
```
主要问题点:
1. 函数 `fun` 的参数 `n` 没有指定类型;
2. 在 `if` 语句中应该使用双等号判断相等,而不是单等号赋值;
3. 函数 `fun` 的返回值缺少返回类型;
4. `main` 函数应该有返回值,并在函数结尾使用 `return 0` 表示正常退出。
相关问题
#include<stdio.h> int main(void) { /*********Found************/ char yy[200] = "ok?
`#include<stdio.h>` 是 C 语言中的预处理指令,用于包含标准输入输出库(stdio)的头文件。这个头文件定义了 C 程序中常用的标准输入输出函数,如 `printf`、`scanf` 和 `fopen` 等。
在给出的代码片段中,`main()` 函数是程序的入口点,标志着程序的开始。`char yy[200] = "ok?"` 是一个字符数组声明,用来存储字符串 "ok?",数组长度为 200 个字符,包括结束符 '\0'。
`/*********Found************/` 这部分是一个标记,可能是为了注释或指示某个特定部分。通常情况下,如果 `yy` 数组被用作用户输入的接收器,它可能会与 `scanf` 函数一起使用。
相关问题--
1. 什么头文件包含了输入输出函数?
2. `main()` 函数在 C 程序中的作用是什么?
3. 描述一下字符数组在 C 语言中的用途。
#include <stdio.h> int fun(double x[], int n) { /************found**********
这是一道C语言的题目,函数fun的作用是将数组x中的元素按照从小到大的顺序排序,并返回排序后的数组中元素个数。下面是完整的代码实现:
```c
#include <stdio.h>
int fun(double x[], int n) {
int i, j;
double temp;
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (x[i] > x[j]) {
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
return n;
}
int main() {
int n, i;
double x[100];
printf("Please input(n>0): ");
scanf("%d", &n);
printf("Please input %d numbers:\n", n);
for (i = 0; i < n; i++) {
scanf("%lf", &x[i]);
}
n = fun(x, n);
printf("\nThe sorted array is:\n");
for (i = 0; i < n; i++) {
printf("%g ", x[i]);
}
printf("\n");
return 0;
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)