求vc6程序:输入一个元素查找数组内是否存在,如果不存在继续输入,重
展开全部
int _tmain(int argc, _TCHAR* argv[])
{
char s1[10] = {0,1,2,3,4,5,6,7,8,9};
//方法一:使用goto
int state1 = 0;
int input1 = 0;
lp:scanf("%d",&input1);
for(int i = 0;i<10;i++)
{
if(s1[i] == input1)
{
state1 = 1;
break;
}
}
if(state1 == 1)
printf("%d is exist\n",input1);
else
goto lp;
//方法二:使用循环
int state2 = 0;
int input2 = 0;
while(state2 ==0)
{
scanf("%d",&input2);
for(int i = 0;i<10;i++)
{
if(s1[i] == input2)
{
state2 = 1;
break;
}
}
}
printf("%d is exist\n",input2);
system("pause");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询