Slip 11_1: Accept n values in array from user. Accept a value x from user and use sentinel linear search algorithm to check whether the number is present in the array or not and output the position if the number is present

 Solution :

#include<stdio.h>

void sentinelsearch(int a[10],int n,int sr)

{ int i,cnt=0;

 a[n]=sr;

 while(sr!=a[i])

 { i++;

 }

 if(i<n)

 printf("Element is found at %d position ",i);

 else

 printf("element is not found ");

}

main()

{

 int n,i,sr,a[10];

 printf("enter how many values");

 scanf("%d",&n);

 for(i=0;i<n;i++)

 {

 printf("enter values");

 scanf("%d",&a[i]);

 }

 printf("\n enter search element");

 scanf("%d",&sr);

 sentinelsearch(a,n,sr);

}


Comments

Popular posts from this blog

Slip 22_2: Read the data from file 'cities.txt' containing names of cities and their STD codes. Accept a name of the city from user and use sentinel linear search algorithm to check whether the name is present in the file and output the STD code, otherwise output “city not in the list”. Solution :

Slip10_2, 30_1 : Read the data from the file “employee.txt” and sort on names in alphabetical order (use strcmp) using bubble sort or selection sort

Slip 23_2: Read the data from file ‘sortedcities.txt’ containing sorted names of cities and their STD codes. Accept a name of the city from user and use binary search algorithm to check whether the name is present in the file and output the STD code, otherwise output “city not in the list”.