Advertisement
programmer1997

P3.c

Nov 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 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.     int new_vol = 0.75 * 256;
  11.  
  12.     srand(1);
  13.  
  14.     arr = (int16_t*) calloc(size, sizeof(int16_t));
  15.  
  16.     for(count = 0; count < size; count++){
  17.         arr[count] = (rand() % 65537) - 32769;
  18.     }
  19.  
  20.     clock_t begin = clock();
  21.  
  22.     for(count = 0; count < size; count++){
  23.         arr[count] = (arr[count] * new_vol) >> 8;
  24.     }  
  25.  
  26.     clock_t end = clock();
  27.     double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  28.  
  29.     for(count = 0; count < size; count++){  
  30.         sum += arr[count];
  31.     }
  32.  
  33.     printf("sum is %d\n", sum);
  34.     printf("time taken for part b was %lf\n", time_spent);
  35.  
  36.     free(arr);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement