查找数组中的元素
查找数组中的元素
1.输入数组并输入六个元素,查找数组中的元素伪代码
点击查看伪代码
Integer number[6]
Set position to 0
Set found to FALSE
WHILE(position < 6 AND found is FALSE)
IF(number[poision] equals searchltem
Set found to TURE
ELSE
Set position to position + 1
PRINT found
2.测试
这是C语言代码:
点击查看代码
#include <stdio.h>
int main()
{
int list[] = {60,75,95,80,65,90},num,count = 0;
scanf("%d",&num);
for(;count <= 5;)
{
if(num != list[count])
{
count++;
if(count == 6)
printf("没找到");
}
else
{
printf("找到");
count = 6; //强制跳出循环
}
}
return 0;
}