Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <stddef.h>
- int main (void) {
- int N, i, ii, j;
- scanf ("%d", &N);
- int A[N];
- float random;
- srand(time(NULL));
- for (i=0; i<N; i++){
- random = rand();
- random = (random / RAND_MAX)*10;
- A[i]=random;
- // scanf ("%d", &A[i]);
- }
- clock_t start = clock ( ) ;
- for (j=0; j<N; j++){
- for (i=1; i<N; i++){
- if ( (A[i-1] > A[i]) & (j != i) ){
- ii=A[i];
- A[i]=A[i-1];
- A[i-1]=ii;
- }
- }
- }
- clock_t end= clock ( ) ;
- float seconds = ( float ) ( end - start ) / CLOCKS_PER_SEC;
- /* for (i=0; i<N; i++){
- printf ("%d ", A[i]);
- }
- */
- printf (" \n");
- printf ("%f ", seconds);
- return 0;
- }
Add Comment
Please, Sign In to add comment