当前位置:网站首页>Exercise 8-2 finding a specified element in an array (15 points)
Exercise 8-2 finding a specified element in an array (15 points)
2022-06-11 22:25:00 【Xiaoyan y】
This problem requires the implementation of a simple function to find the specified elements in the array .
Function interface definition :
int search( int list[], int n, int x );
among list[] Is the array passed in by the user ;n(≥0) yes list[] The number of elements in ;x Is the element to be found . If you find
The function search Returns the minimum subscript of the corresponding element ( Subscript from 0 Start ), Otherwise return to −1.
Sample referee test procedure :
#include <stdio.h>
#define MAXN 10int search( int list[], int n, int x );
int main()
{
int i, index, n, x;
int a[MAXN];scanf("%d", &n);
for( i = 0; i < n; i++ )
scanf("%d", &a[i]);
scanf("%d", &x);
index = search( a, n, x );
if( index != -1 )
printf("index = %d\n", index);
else
printf("Not found\n");return 0;
}/* Your code will be embedded here */
sample input 1:
5
1 2 2 5 4
2
sample output 1:
index = 1
sample input 2:
5
1 2 2 5 4
0
sample output 2:
Not found
int search( int list[], int n, int x ){
int i;
for(i=0;i<n;i++){
if(list[i]==x){
return i;
break;
}
}
return -1;
}
边栏推荐
- Dynamics 365 选项集操作
- Basic operation and question type summary of linked list
- Tkinter学习笔记(三)
- Why is the printer unable to print the test page
- Submit task to thread pool
- 完好性简要介绍
- Read dense visual slam for rgb-d cameras
- C language implements eight sorts (1)
- Unity3d getlaunchintintforpackage getting package returned null
- Are you still using localstorage directly? It's time to raise the bar
猜你喜欢

Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.4

Matplotlib和tkinter学习笔记(一)

How to adjust the font blur of win10

One question per day -- verifying palindrome string

超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄

論文閱讀《Dense Visual SLAM for RGB-D Cameras》

SVN本地部署server和cleint 并用阿里云盘自动备份

Basic operation of graph (C language)

Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.2

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录
随机推荐
Matlab point cloud processing (XXIV): point cloud median filtering (pcmedian)
Analysis of the implementation principle of an open source markdown to rich text editor
What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)
习题6-6 使用函数输出一个整数的逆序数 (20 分)
使用VBScript读取网络的日志数据进行处理
Inner join execution plan changed
A simple example of linear regression in machine learning
[Yu Yue education] Yancheng Normal University Advanced Algebra reference
重温c语言一
论文阅读《Dense Visual SLAM for RGB-D Cameras》
astra pro双目相机ros下启动笔记
Submit task to thread pool
Players must read starfish NFT advanced introduction
Regular execution of shell scripts in crontab
Dynamic memory management (1)
Tkinter study notes (IV)
926. 将字符串翻转到单调递增
启牛推荐开通的证券账户安全吗?靠谱吗
【解决】修改子物体Transform信息导致变换不对称、异常问题的解决方案
Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.4