用c语言数组编写,内容:用函数的形式判别一个整数数组a[10]={1,2,3,4,-1,-2,-3,-4,2,3}中各元素值,若大于0则输出该值,否则输出0值。
时间: 2024-05-02 20:22:25 浏览: 23
您好!非常感谢您使用ChitGPT进行对话。针对您的问题,以下是C语言代码的实现:
```
#include<stdio.h>
void judge(int a[10]) {
for(int i=0;i<10;i++) {
if(a[i]>0) {
printf("%d ", a[i]);
} else {
printf("0 ");
}
}
}
int main() {
int a[10]={1,2,3,4,-1,-2,-3,-4,2,3};
judge(a);
return 0;
}
```
这个程序首先定义一个名为judge的函数,通过循环遍历整数数组a中的每个元素,如果该元素大于0,则输出该元素的值,否则输出0。在主函数中,我们定义了一个整数数组a并将其作为参数传递给judge函数进行处理,最后输出处理结果。希望对您有所帮助!
相关推荐
![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_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.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_column_c1.png)