减治法计算数组中的零个数

题目描述

给定一个整数数组,使用减治法计算数组中的零个数

输入格式:

第一行请输入数组元素个数

第二行请输入数组的元素值

输入样例:

复制代码
4
1 2 0 4

输出样例:

复制代码
1

#include<stdio.h>

int countZero(int arr\[\], int n) {

if (n==0) {

return 0;

} else {

if (arrn-1==0) {

return 1+countZero(arr,n-1);

} else {

return countZero(arr,n-1);

}

}

}

int main(){

//请在此处开始编写你的代码

int n;

printf("Enter the size of the array:");

scanf("%d",&n);

int arrn;

printf("Enter the elements of the array:");

for (int i=0;i<n;i++) {

scanf("%d",&arri);

}

int count=countZero(arr,n);

printf("The number of zero elements in the array is:%d\n",count);

return 0;

}

相关推荐
不正经学生2 小时前
C语言预处理详解:编译器真正动手之前的那些事
c语言·开发语言·算法·面试·bug
毕竟是shy哥5 小时前
计算YOLO数据集中每个类的目标数
算法·yolo·机器学习
M78佐菲5 小时前
Linux学习笔记:TCP协议
linux·笔记·学习·tcp/ip·算法
圣保罗的大教堂5 小时前
leetcode 1406. 石子游戏 III 困难
leetcode
晊晌_h6 小时前
嵌入式从0到精通——数据结构总结[特殊字符]
数据结构·算法·排序算法
我找到地球的支点啦7 小时前
Matlab系列(009) 一CRC循环冗余校验详解
开发语言·数据结构·算法·matlab·信息与通信
罗西的思考7 小时前
【OpenClaw具身硬件】ZeroClaw 源码阅读笔记(3)--- RAG
人工智能·算法·机器学习
浪里镖客8 小时前
位姿转换矩阵写法-个人习惯(计算机理解其实是相反的)
线性代数·算法·矩阵
小白羊丨11 小时前
如何诊断 Prompt 模板导致的效果下降?
人工智能·算法·prompt
OPEN-F12 小时前
C++11/14新特性精讲:移动语义与智能指针实战
开发语言·c++·算法