Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.  
  6. #define ANTAL_RUNDER 15
  7.  
  8.  
  9. int main(void){
  10.  
  11. /* SET RAND-SEED */
  12. srand(time(NULL));
  13.  
  14. /* PROMPT FOR INPUT. N = ANTAL TERNINGER */
  15. int n;
  16. printf("indtast antal terninger: ");
  17. scanf("%d", &n);
  18.  
  19. int **array;
  20. array = malloc(ANTAL_RUNDER * sizeof(int));
  21. if (array == NULL){
  22. printf("could not allocate memory");
  23. return EXIT_FAILURE;
  24. }
  25.  
  26. int i;
  27. for ( i = 0; i < ANTAL_RUNDER; i++){
  28. array[i] = malloc(n * sizeof(int));
  29. if (array[i] == NULL){
  30. printf("could not allocate memory");
  31. return EXIT_FAILURE;
  32. }
  33. }
  34.  
  35. int j;
  36. for (i = 0; i < ANTAL_RUNDER; i++){
  37. for ( j = 0; j < n; j++){
  38. array[i][j] = rand()% 6 + 1;
  39. printf("%d ", array[i][j]);
  40. }
  41. printf("\n");
  42. }
  43.  
  44. /* POINT SYSTEM */
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. for ( i = 0; i < n; i++){
  59. free(array[i]);
  60. }
  61. free(array);
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement