C

Searching:

Example:

//Write a Program To Search a Given Value in One-dimensional Array.
#include<stdio.h>
#include<conio.h>
#define MAX 5

void main()
{
    int a[MAX],i,num,flag=0;
    clrscr();
    printf("Enter Any %d Number\n\n",MAX);
    for(i=0;i<MAX;i++)
    {
        printf("Enter Value of a[%d] = ",i);
        scanf("%d",&a[i]);
    }
    printf("Enter Value For Serching Array Num: ");
    scanf("%d",&num);
    for(i=0;i<MAX;i++)
    {
        if(num == a[i])
        {
            printf("\n%d Is Found On a[%d] Position",a[i],i);
            flag=1;
            break;
        }
    }
    if(flag!=1)
    {
        printf("\nNumber Is Not Found");
    }
    getch();
}

Output:

Command Prompt
Enter Any 5 Number

Enter Value of a[0] = 5
Enter Value of a[1] = 50
Enter Value of a[2] = 30
Enter Value of a[3] = 100
Enter Value of a[4] = 250
Enter Value For Searching Array Num: 100
100 Is Found On a[3] Position



Subscribe us on Youtube

Share This Page on


Ask Question