Sunday, 26 October 2014

Array Search

Non-Recursive C Program:

Aim:
To search a element in a array elements

Program:
#include<stdio.h>
#include<conio.h>
void main ()
{
   int A[25],i,num,flag=0,position,m;

printf("Enter the size of array:");
scant("%d",&m);

printf("\n Enter the numbers:");
  for(i=0;i<m;i++)
    {
       scanf("%d",&A[i]);
    }

printf("\n The Elements of array:");
for(i=0;i<m;i++)
    {
       printf("%d\t",A[i]);
    }

printf("\n Enter the number to be search:");
scant("%d",&num);

for(i=0;i<m;i++)
    {
       if(num==A[i])
         {
            flag=1;
            break;
          }
    }
   if( flag==1)
printf("\n Search successful, the number %d is found at %d position ",num,i+1);
    else
printf("\nSearch unsuccessful,the number %d is not found ",num);
}

Output:
Enter the size of array : 10
Enter the numbers:
19
21
32
43
54
65
76
87
98
100
Enter the number to be search: 87
The number 87 found at 8 position.

1 comment:

  1. Casino Review & Ratings - JeRHub
    Our casino review looks at 아산 출장안마 the 충청북도 출장마사지 main 광양 출장샵 bonuses and free spins 밀양 출장마사지 offers, promotions and deposit methods and features. Rating: 3.9 의정부 출장샵 · ‎Review by TJ Hub

    ReplyDelete