Student Roll No

If she has to 10 students ordered list for the subject DS from 1 to 15.Now she wants to find roll no:5 belongs to her or not?

#include <stdio.h>
int main()
{
int array[10];
  int i,j,temp;
  int low,mid,high;
  for(i=0;i<10;i++)
  {
    scanf("%d", &array[i]);
  }
    for(i=0;i<10;i++)
    {
    //  printf("%d",array[i]);
    }
  for(i=0;i<10;i++)
  {
    for(j=0;j<(10-i-1);j++)
    {
      if(array[j]>array[j+1])
      {
        temp=array[j];
        array[j]=array[j+1];
        array[j+1]=temp;
      }
    }
  }
  printf("Sorted Rollnumber list is\n");
  for(i=0;i<10;i++)
  {
    printf("%d ",array[i]);
  }
  low=1;
  high=5;
  do
  {
    mid = (low+high)/2;
    if(5<array[mid])
      high = mid -1;
    else if(5>array[mid])
      low=mid+1;
  }
  while(5!=array[mid]&&low<=high);
  if(5==array[mid])
  {
    printf("\nRoll no 5 belongs to the list");
  }
  else
  {
    printf("\nRoll no 5 does not belong to the list");
  }
  
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.