查找数组中元素
伪代码
固定长度为6
set position to 0
Write “enter value for which to search”
Read searchitem=75
Set found to true if searchitem is there
While (position <6)
IF(found)
Write “found”
continue
ELSE
Write ”found”
found Position 1-->75
Continue can not found
end
c语言代码
include <stdio.h>
int main(void)
{
int list[5] = {25,30,35,40,45};
int i = 0,m;
printf("Enter a number:");
scanf("%d",&m);
while (i<=5)
{
if (m != list[i])
i++;
else
break;
}
if (i == 6)
printf("Can not found");
else
printf("Number %d is found",m);
return 0;
}
posted on 2022-10-09 19:20 20221305赵月溪 阅读(3) 评论(0) 编辑 收藏 举报