Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define N 30
  5. typedef int tab[N];
  6. typedef int tab1[9];
  7. //===========================================//
  8. void wypelnij(tab t)
  9. {
  10. int i;
  11. i=0;
  12. while(i<N)
  13. {
  14. t[i]=rand()%9;
  15. i++;
  16. }
  17. }
  18. //===========================================//
  19. void wypisz(tab t)
  20. {
  21. int i;
  22. for(i=0;i<N;i++)
  23. {
  24. printf(" %d",t[i]);
  25. }
  26. }
  27. //===========================================//
  28. void licz(tab t)
  29. {
  30. int i,j,ilosc;
  31. for(i=0;i<N;i++)
  32. {
  33. ilosc=0;
  34. for(j=0;j<N;j++)
  35. {
  36. if(t[i]==t[j])
  37. {
  38. ilosc=ilosc+1;
  39. }
  40. }
  41. printf("Liczba %d, wystepuje %d razy \n\n",t[i],ilosc);
  42. }
  43. }
  44. //===========================================//
  45. void liczebnosc(tab t,tab1 t1)
  46. {
  47. int i;
  48. int j;
  49. int indeks;
  50. for(j=0;j<=8;j++)
  51. {
  52. t1[j]=0;
  53. }
  54. for(i=0;i<N;i++)
  55. {
  56. indeks=t[i];
  57. t1[indeks]=t1[indeks]+1;
  58. }
  59. for(j=0;j<=8;j++)
  60. {
  61. printf("Liczba %d, wystepuje %d razy \n\n",j,t1[j]);
  62. }
  63. }
  64. //===========================================//
  65. void sort(tab t)
  66. {
  67. int i,j,tmp;
  68. for(i=0;i<N-1;++i)
  69. {
  70. for(j=0;j<N-1-i;j++)
  71. {
  72. if(t[j+1]<t[j])
  73. {
  74. tmp=t[j];
  75. t[j]=t[j+1];
  76. t[j+1]=tmp;
  77. }
  78. }
  79. }
  80. }
  81. //===========================================//
  82. int main()
  83. {
  84. tab tablica;
  85. tab1 tablica1;
  86. srand(time(0));
  87. wypelnij(tablica);
  88. puts("Tablica poczatkowa:");
  89. wypisz(tablica);
  90. puts("");
  91. puts("");
  92. puts("Liczebnosc bez usuniecia zbednych czesci:");
  93. licz(tablica);
  94. puts("");
  95. puts("");
  96. puts("");
  97. puts("Liczebnosc dzialajaca poprawnie:");
  98. liczebnosc(tablica,tablica1);
  99. sort(tablica);
  100. puts("");
  101. puts("Tablica po wykonaniu sortowaniu:");
  102. wypisz(tablica);
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement