Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #define n 10000
  5. void timilas()
  6. {
  7. int X[n], A[n],i,s,j;                  
  8. for (i=0;i<n;i++) {                
  9.      s = X[0];                 
  10.      for (j=1; j<=i; j++)          
  11.           s = s + X[j];                
  12.      A[i] = s;                 
  13. }
  14. }  
  15. void Eh(){
  16. int X[n], A[n], i, s;
  17. s = 0;                     
  18. for (i=0; i<n; i++) {              
  19.      s = s + X[i];             
  20.      A[i] = s;                     
  21. }
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. main()
  30. {
  31.       int k;
  32.       clock_t start=clock();
  33.       timilas();
  34.       clock_t stop=clock();
  35.       double duration=(double) (stop-start)*1000.0/CLOCKS_PER_SEC;
  36.       printf("Durations(ms):%4.0f\n",duration);
  37.        
  38.         start=clock();
  39.     for(k=0;k<1000;k++)
  40.     {
  41.     Eh();
  42. }
  43.    system("pause");
  44.  
  45.       stop=clock();
  46.       duration=(double) (stop-start)*1000.0/CLOCKS_PER_SEC;
  47.       printf("Durations(ms):%4.4f\n",duration/1000);
  48.       system("pause");
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement