如何完成编码以使用线性搜索查找字符 [英] How Can I Complete The Coding To Find The Character Using Linear Search

查看:59
本文介绍了如何完成编码以使用线性搜索查找字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>


int main( )
{
    char status[] = {'s','i','m','p','l','e' } ;
    char i, x ;



    printf ( "Enter character to search: " ) ;
    scanf ( "%c", &x ) ;

    for(i=0;i<=5;i++)
    {
        if ( status[5] < x || status[i] >= x )
        {
             if ( status[5] == x)
                printf ( "The character is at position %d in the array.", i ) ;
            else
                printf ( "character is not present in the array." ) ;
            break ;
        }
    }

}

推荐答案

不确定其中的一些代码就在那里!只需取出多余的:

Not sure quite what some of that code is there for! Just take out the excess:
int main( )
{
    char status[] = {'s','i','m','p','l','e' } ;
    char i, x ;
    printf ( "Enter character to search: " ) ;
    scanf ( "%c", &x ) ;
    for(i=0;i<6;i++)
    {
        if ( status[i] == x ) break;
    }
    if (i < 6)
        printf ( "The character is at position %d in the array.", i);
    else
        printf ( "character is not present in the array." ) ;
}


这篇关于如何完成编码以使用线性搜索查找字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆