Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. int N=3;
  6. int **tab;
  7. int x;
  8.  
  9. int main() {
  10. /*tab=(int **) malloc(N*sizeof(int *));*/
  11. tab=(int **) calloc(N, sizeof(int *));
  12. if (tab == NULL)
  13. {
  14. return -1;
  15. };
  16.  
  17.  
  18. for(int i=0;i<N; i++)
  19. {
  20. /*tab[i]=(int *) malloc(N*sizeof(int));*/
  21. tab[i]=(int *) calloc(N, sizeof(int));
  22. }
  23.  
  24. for(int i=0;i<N;i++)
  25. {
  26. for(int j=0;j<N;j++)
  27. {
  28. printf("%4i", tab[i][j]);
  29. }
  30. printf("\n");
  31. }
  32.  
  33. printf("\n");
  34.  
  35.  
  36. srand(time(NULL));
  37.  
  38. for(int i=0;i<N;i++)
  39. {
  40. for(int j=0;j<N;j++)
  41. {
  42. x=rand()%10+1;
  43. tab[i][j]=x;
  44. }
  45. }
  46.  
  47. for(int i=0;i<N;i++)
  48. {
  49. for(int j=0;j<N;j++)
  50. {
  51. printf("%4i", tab[i][j]);
  52. }
  53. printf("\n");
  54.  
  55. }
  56.  
  57.  
  58. for(i=0;i<N;i++)
  59. {
  60. free
  61. }
  62. system("pause");
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement