Skip to content

Instantly share code, notes, and snippets.

@RakibOFC
Created October 13, 2020 02:07
Show Gist options
  • Save RakibOFC/4ced77ee5efbe1490c4fbcf260d2ea97 to your computer and use it in GitHub Desktop.
Save RakibOFC/4ced77ee5efbe1490c4fbcf260d2ea97 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int i, j, a[300000], num, temp;
double start, end;
srand(time(0));
printf("Enter input size: ");
scanf("%d", &num);
printf("\nInput Array: ");
for(i = 0; i < num; i++)
{
a[i] = rand()%1000;
printf("%d ", a[i]);
}
start = clock();
for(i = 0; i < num; i++)
{
for(j = 0; j < num-i-1; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
end = clock();
printf("\n\nSort: ");
for(i = 0; i < num; i++)
{
printf("%d ", a[i]);
}
printf("\n\nExecution time: %.3lf s\n\n", (end-start)/1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment