Guest User

Untitled

a guest
Oct 2nd, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #define N 40
  2.  
  3. #include <stdio.h> //für printf()
  4. #include <time.h> //für clock()
  5. #include <stdlib.h> //für rand()
  6. #include "array.cpp"
  7.  
  8. extern void sort(int Array[]);
  9.  
  10. int main()
  11. {
  12.     int A[N]={0,6,7,7,3,1,0,3,6,4,7,9,2,1,3,9,4,9,9,9,2,4,2,0,7,5,7,2,8,9,3,5,3,4,8,1,4,9,5,1};
  13.     int time1,time2,thou,sec;
  14.  
  15.     time1 = clock();
  16.  
  17.     sort(A);
  18.    
  19.     time2 = clock();
  20.  
  21.     for(int i=0; i < N; i++)
  22.         {
  23.             printf("%d",A[i]);
  24.         }
  25.    
  26.     printf("\nTime1: %i",time1);
  27.     printf("\nTime2: %i",time2);
  28.     printf("\nDiff : %i",time2-time1);
  29.     thou  = (time2-time1) * 1000 / CLOCKS_PER_SEC;
  30.     sec   = thou / 1000;
  31.     thou -= sec * 1000;
  32.     printf ("\nDie Zeit fuer 80.000 Elemente betraegt: %ld.%09ld sec.\n\n", sec, thou,"\n");
  33.    
  34.     /*RANDOM-Generator: schreibt 40x2000 Random-Zahlen in eine Textdatei
  35.     srand (time(NULL));
  36.     char string[80]={'x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',',','x',','};
  37.     FILE * pFile;
  38.     pFile = fopen ("array.txt","w"); //a+: Update w: Neu schreiben/ueberschreiben
  39.     if (pFile!=NULL)
  40.     {
  41.         for(int i=0; i < 2000; i++)
  42.             {
  43.                 for(int j=0; j < 40; j++) //Neue Zeile generieren
  44.                     {
  45.                         string[i*2] = rand() % 10 + 48; //ASCII 48d...57d: '0'...'9'
  46.                     }
  47.                 for(int k=0; k < 80; k++) //Zeile schreiben
  48.                     {
  49.                         fputc (string[j],pFile);
  50.                     }
  51.                 fputc ('\n',pFile); //Newline
  52.             }
  53.         fclose (pFile);
  54.     }*/
  55.  
  56.     getchar();
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment