Advertisement
programmer1997

P1.c

Nov 22nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. void main(){
  7.  
  8.     int16_t *arr;
  9.     long long int sum = 0, size = 500000000, count = 0;
  10.    
  11.     srand(1);
  12.  
  13.     arr = (int16_t*) calloc(size, sizeof(int16_t));
  14.  
  15.     for(count = 0; count < size; count++){
  16.         arr[count] = (rand() % 65537) - 32769; 
  17.     }
  18.  
  19.     clock_t begin = clock();
  20.  
  21.     for(count = 0; count < size; count++){
  22.         arr[count] *= 0.75;
  23.     }  
  24.  
  25.     clock_t end = clock();
  26.     double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  27.  
  28.     for(count = 0; count < size; count++){  
  29.         sum += arr[count];
  30.     }
  31.  
  32.     printf("sum is %d\n", sum);
  33.     printf("time taken for part b was %lf\n", time_spent);
  34.  
  35.     free(arr);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement