Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define N 16
  5. #define M 16
  6.  
  7. int histogram (int dane[], int l, int hist[], int m)
  8. {
  9. int i;
  10. for(i=0; i<m; i++)
  11. hist[i]=0;
  12. for(i=0; i<l; i++)
  13. hist[dane[i]]++;
  14. }
  15.  
  16.  
  17.  
  18. int min (int tabl[], int p)
  19. {
  20.  
  21. int i, minl, j, minw, w, l;
  22. minl=0;
  23.  
  24. for(i=0; i<N; i++)
  25. {
  26. w = tabl[i]; l=0;
  27. for(j=0; j<N; j++)
  28. if (tabl[j] != w) l++;
  29. if(l>=minl)
  30. {
  31. minl = 1; minw = w;
  32. }
  33. }
  34. printf("Najrzadziej wystepujaca wartoscia jest %d.", minw);
  35. }
  36.  
  37.  
  38.  
  39.  
  40. int max (int tab[], int k)
  41. {
  42. int i, maxl, j, maxw, w, l;
  43. maxl=0;
  44.  
  45. for(i=0; i<N; i++){
  46. w=tab[i]; l=0;
  47. for(j=0; j<N; j++)
  48. if (tab[j]!= w) l++;
  49. if(l>=maxl)
  50. {
  51.  
  52. maxl = l; maxw = w;
  53. }
  54. }
  55. printf("Najczesciej wystepujaca wartoscia jest %d.", maxw);
  56. }
  57. int main()
  58. {
  59. int a[N], h[M], i;
  60. srand(time(NULL));
  61. printf("Tablica ll");
  62. for(i=0; i<N; i++){
  63. a[i]=rand()%5;
  64. }
  65. for(i=0; i<N; i++){
  66. printf("%4d", a[i]);
  67. }
  68. printf("\n\n");
  69. histogram(a,N,h,M);
  70. printf("tablica in");
  71. for(i=0; i<M; i++)
  72. printf("%4d", i);
  73. printf("\n\n");
  74. printf("tablica cw");
  75. for(i=0; i<M; i++)
  76. printf("%4d", h[i]);
  77. printf("\n\n");
  78. max(a,N);
  79. printf("\n\n");
  80. min(a,N);
  81. printf("\n\n");
  82.  
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement