हिंदी

The following code may contain some errors. Identify the errors, modify the program by underlining the changes made, and write the aim of the program. int RA[ ] = {42, 51, 75, 95, 86, 84, 62};

Advertisements
Advertisements

प्रश्न

The following code may contain some errors. Identify the errors, modify the program by underlining the changes made, and write the aim of the program.

int RA[ ] = {42, 51, 75, 95, 86, 84, 62};
boolean fnLinearSearch(int val)
{
    for(int p = RA.length;p >=0; p--)
    {
        if(RA[p] = val)
        {
           break;
        }
    }
    if(p >= 0)
    return true;
    return false;
}
कोड लेखन
Advertisements

उत्तर

Syntax Error: p = RA.length will cause an error: array index out of bounds.

Syntax Error: p has been used outside the loop so it cannot be the loop counter

int RA[ ] = {42, 51, 75, 95, 86, 84, 62};
boolean fnLinearSearch(int val)
{
    int p = 0;
    for(p = RA.length - 1; p>=0; p--)
    {
       if(RA[p]= val)
       {
           break;
       }
    }
    if(p >=0)
    return true;
    return false;
}

Aim: The aim of the programme is to search for an element in an array using linear search.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 8: Arrays - Sort & Search - Exercises [पृष्ठ १९९]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 8 Arrays - Sort & Search
Exercises | Q 3. (iii) | पृष्ठ १९९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×