#include<stdio.h>
int find_smallest_element_position(int *a, int first , int last); main() { int a[10]={4,5,6,7,8,9,1,2,3}; int pos; pos=find_smallest_element_position(a,0,8); printf("The smallest element's position is %d\n",pos); } int find_smallest_element_position(int *a, int first , int last) { int mid; while(first<last) { mid=(first+last)/2; if(a[mid]>a[last]) { first=mid+1; } else { last=mid; } } return first; }
No comments:
Post a Comment