hi.can u plz tell me where to put printf for timecount.here is the code for quicksort i wanted to calculate the time it takes.

#include< stdio.h>
#include< conio.h>
#include <time.h>
#include <ctime>


void shellsort(int a[],int n)
{
int j,i,k,m,mid;
for(m = n/2;m>0;m/=2)
{
for(j = m;j< n;j++)
{
for(i=j-m;i>=0;i-=m)
{
if(a[i+m]>=a[i])
break;
else
{
mid = a[i];
a[i] = a[i+m];
a[i+m] = mid;
}
}
}
}
}

main()
{ int timecount;
clock_t startClock,finishClock;
double timeCount;
startClock = clock();

int a[10],i,n;

printf("Enter The number Of Elements\t: ");
scanf("%d",&n);
for(i=0;i< n;i++)
{
printf("\nElement %d\t: ",i+1);
scanf("%d",&a[i]);
}

printf("\nArray Befor Sorting : ");
for(i=0;i< n;i++)
printf("%5d",a[i]);
shellsort(a,n);

printf("\nArray After Sorting : ");
for(i=0;i< n;i++)
printf("%5d",a[i]);


getch();
return 0;
finishClock = clock();
timeCount = finishClock - startClock ;
printf("%d.",timecount);
}

Recommended Answers

All 2 Replies

Well
1. , if i am not wrong ur working on turbo C compiler .
2. there is a help documentation in that itself on how to use the clock function.
3.it would be better , to print (end-start)/clk_tck
4. The output u will fetch will be 0 seconds for the basic operational code.
i.e if the clock is been started when the actual quicksort happens not when ur entering the numbers.

5. Please stop using turbo C , compiler .... there are much better ones than this outdated one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.