I'm supposed to do a sequential earch on integers and also retun the time elapsed on doing such a search . Here is what I have.
Code:
#include<stdio.h>
#include<conio.h>
#include<time.h>
void selection(int a[] , int n);
void main()
{
int a[20],i,n;
clrscr();
printf("enter the no. of elemnts ");
scanf("%d",&n);
printf("enter elemnts");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
selection(a,n);
getch();
}
void selection ( int a[], int n)
{
int i,j,temp,min;
clock_t st,end;
st= clock();
for(i=0;i<=n-2;i++)
{
min=i;
for(j=i+1;j<=n-1;j++)
{
if( a[j]<a[min]) min=j;
}
temp= a[i];
a[i]= a[min];
a[min]=temp;
}
end= clock();
printf("sorted array is ....");
for(i=0;i<n;i++){
printf("%d",&a[i]);}
printf("elapsed time is ..%f",(end-st)/CLK_TCK);
}
While the sorting works okay the time elapsed is always 0.00000. why? and how to make it okay?