Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <stdarg.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <stdio.h>
  7. #include <math.h>
  8.  
  9. INSERT_RESULT_TYPE_HERE create_hist( INSERT_FORMAL_PARAMETERS_HERE ) {
  10. // TODO: INSERT CODE HERE
  11. }
  12.  
  13. void call_function( const char * label, double x[], int count ) {
  14. int hist[22 + 1];
  15. create_hist( x, count, hist );
  16. printf( "%s\n", label );
  17. printf( "\tInput data:\n" );
  18.  
  19. for ( int i = 0; i < count; i++ ) {
  20. printf( "\t%d\t%f\n", i, x[i] );
  21. }
  22.  
  23. printf( "\tHistogram:\n" );
  24.  
  25. for ( int i = 0; i <= 22; i++ ) {
  26. printf( "\t%d\t%d\n", i, hist[i] );
  27. }
  28.  
  29. printf( "\n" );
  30. }
  31.  
  32. int main( void ) {
  33. srand( time( NULL ) );
  34.  
  35. double x1[] = { 0 };
  36. call_function( "Count == 0", x1, 0 );
  37.  
  38. double x2[] = { 0, 0, 0 };
  39. call_function( "Three equal values", x2, 3 );
  40.  
  41. double x3[22 + 1];
  42. for ( int i = 0; i <= 22; i++ ) {
  43. x3[i] = i;
  44. }
  45. call_function( "One value in each bucket", x3, 22 + 1 );
  46.  
  47. double x4[22 * 2 + 1];
  48. for ( int i = 0; i <= 22 * 2; i++ ) {
  49. x4[i] = (22+1) * ( double ) rand() / RAND_MAX;
  50. }
  51. call_function( "Random values", x4, 22 * 2 + 1 );
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement