0% found this document useful (0 votes)
27 views

Array

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Array

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// 

#include <stdio.h>
// int main()
// {
//     int x;
//     int iValue;
//     int iFound = -1;
//     int iArray[5];
//     for (x = 0; x < 5; x++)
//         iArray[x] = (x + x); //initialize array
//     printf("\nEnter value to search for: ");
//     scanf("%d", &iValue);
//     for (x = 0; x < 5; x++)
//     {
//         if (iArray[x] == iValue)
//         {
//             iFound = x;
//             break;
//         }
//     } //end for loop
//     if (iFound > -1)
//         printf("\nI found your search value in element %d\n", iFound);
//     else
//         printf("\nSorry, your search value was not found\n");
// } //end main

#include <stdio.h>
int main()
{
    int iTwoD[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    int iFoundAt[2] = {0, 0};
    int x, y;
    int iValue = 0;
    int iFound = 0;
    printf("\nEnter your search value: ");
    scanf("%d", &iValue);
    //search the 2-D array
    for (x = 0; x <= 2; x++)
    {
        for (y = 0; y <= 2; y++)
        {
            if (iTwoD[x][y] == iValue)
            {
                iFound = 1;
                iFoundAt[0] = x;
                iFoundAt[1] = y;
                break;
            } //end if
        }     //end inner loop
    }         //end outer loop
    if (iFound == 1)
        printf("\nFound value in iTwoD[%d][%d]\n", iFoundAt[0], iFoundAt[1]);
    else
        printf("\nValue not found\n");
}

You might also like