Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. void funkcja(int n, int *t)
  7. {
  8.  
  9. int i;
  10.  
  11. for (i=0; i<n; i++)
  12. {
  13. *(t + i)= i * i;
  14. printf("\n%d", *(t + i));
  15.  
  16. }
  17.  
  18. free(t);
  19.  
  20. }
  21.  
  22. void funkcja2(int w, int k, double **a)
  23. {
  24.  
  25. printf("\n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \n");
  26.  
  27.  
  28. int i,j;
  29.  
  30. for ( i = 0; i < w; ++i, printf("\n") )
  31. for (j = 0; j < k; ++j)
  32. printf("%.1f\t",a[i][j]);
  33.  
  34. }
  35.  
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39.  
  40. int *t, i,n;
  41.  
  42. t = (int*)malloc(10 *sizeof(int));
  43. if (!t)
  44. {
  45. printf ("brak wolnej pamięci");
  46. exit(1);
  47. }
  48. for (i=0; i<10; i++)
  49. {
  50. *(t + i)= i * i;
  51. printf("\n%d", *(t + i));
  52.  
  53. }
  54. printf("\n%p",t);
  55.  
  56. free (t);
  57.  
  58.  
  59.  
  60. puts("\n podaj n \n");
  61. scanf("%d", &n);
  62. t = (int*)calloc(n,sizeof(int));
  63.  
  64. printf("\n%p",t);
  65.  
  66. for (i=0; i<n; i++)
  67. {
  68. *(t + i)= i * i;
  69. printf("\n%d", *(t + i));
  70.  
  71. }
  72.  
  73. funkcja(n, t);
  74.  
  75. printf("\n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \n");
  76.  
  77. int w,k, j;
  78. printf("Liczba wierszy: ");
  79. scanf("%d",&w);
  80. printf("Liczba kolumn: ");
  81. scanf("%d",&k);
  82. ///////////// 2D /////////////////
  83. printf("\n\nTABLICA 2D - ANSI C\n");
  84. double **tab2;
  85. tab2=(double**)malloc(w*sizeof(double *)); //alokacja pamieci
  86. for(i=0; i<w; i++)
  87. {
  88. tab2[i]=(double*)malloc(k*sizeof(double));
  89. for (j = 0; j < k; ++j) //wpisanie wartosci do tablicy
  90. tab2[i][j]=(i+j)/10.0;
  91. }
  92. //wypisz tab2[w][k]
  93. for ( i = 0; i < w; ++i, printf("\n") )
  94. for (j = 0; j < k; ++j)
  95. printf("%.1f\t",tab2[i][j]);
  96.  
  97.  
  98. funkcja2(w,k, tab2);
  99.  
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement