Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. // W0292378_A6.cpp
  2. // Program created by
  3. // Student ID#
  4. // Assignment #7 - Headers and Source Files
  5. //
  6. // Program Description: This program
  7.  
  8. #include "stdafx.h"
  9. #include <stdlib.h>
  10. #include <ctype.h>
  11. #include <time.h>
  12.  
  13. #define num_of_elements 10
  14.  
  15.  
  16. void genArr();
  17. //int * arrSort(int* a);
  18.  
  19. void main()
  20. {
  21. int i;
  22.  
  23. int randArray[num_of_elements];
  24. genArr(randArray);
  25.  
  26. printf("The contents of this array are: \n");
  27. for (i = 0; i < num_of_elements; i++) {
  28. printf("randArray[%d]: %d\n", i, *(randArray + i));
  29. }
  30.  
  31. //printf("The sorted contents of the array are: \n");
  32. //arrSort(randArray);
  33. //for (i = 0; i < num_of_elements; i++) {
  34. // printf("randArray[%d]: %d\n", i, *(randArray + i));
  35. //}
  36.  
  37.  
  38. system("pause");
  39. }
  40.  
  41. void genArr(int * a) {
  42. int i;
  43. time_t t;
  44. srand((unsigned)time(&t));
  45. for (i = 0; i < num_of_elements; i++) {
  46. a[i] = rand() % 51;
  47. }
  48. return;
  49. }
  50.  
  51. //int* arrSort(int* a){
  52. // int i, j;
  53. //
  54. // for (int i = 0; i < num_of_elements; i++) {
  55. //
  56. // for (j = 0; j < num_of_elements; j++) {
  57. //
  58. // if (*(a + j) > *(a + i))
  59. // {
  60. // int tmp = *(a + i); //Using temporary variable for storing last value
  61. // *(a + i) = *(a + j); //replacing value
  62. // *(a + j) = tmp;
  63. // }
  64. // }
  65. // return a;
  66. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement