Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 30
- typedef int tab[N];
- typedef int tab1[9];
- //===========================================//
- void wypelnij(tab t)
- {
- int i;
- i=0;
- while(i<N)
- {
- t[i]=rand()%9;
- i++;
- }
- }
- //===========================================//
- void wypisz(tab t)
- {
- int i;
- for(i=0;i<N;i++)
- {
- printf(" %d",t[i]);
- }
- }
- //===========================================//
- void licz(tab t)
- {
- int i,j,ilosc;
- for(i=0;i<N;i++)
- {
- ilosc=0;
- for(j=0;j<N;j++)
- {
- if(t[i]==t[j])
- {
- ilosc=ilosc+1;
- }
- }
- printf("Liczba %d, wystepuje %d razy \n\n",t[i],ilosc);
- }
- }
- //===========================================//
- void liczebnosc(tab t,tab1 t1)
- {
- int i;
- int j;
- int indeks;
- for(j=0;j<=8;j++)
- {
- t1[j]=0;
- }
- for(i=0;i<N;i++)
- {
- indeks=t[i];
- t1[indeks]=t1[indeks]+1;
- }
- for(j=0;j<=8;j++)
- {
- printf("Liczba %d, wystepuje %d razy \n\n",j,t1[j]);
- }
- }
- //===========================================//
- void sort(tab t)
- {
- int i,j,tmp;
- for(i=0;i<N-1;++i)
- {
- for(j=0;j<N-1-i;j++)
- {
- if(t[j+1]<t[j])
- {
- tmp=t[j];
- t[j]=t[j+1];
- t[j+1]=tmp;
- }
- }
- }
- }
- //===========================================//
- int main()
- {
- tab tablica;
- tab1 tablica1;
- srand(time(0));
- wypelnij(tablica);
- puts("Tablica poczatkowa:");
- wypisz(tablica);
- puts("");
- puts("");
- puts("Liczebnosc bez usuniecia zbednych czesci:");
- licz(tablica);
- puts("");
- puts("");
- puts("");
- puts("Liczebnosc dzialajaca poprawnie:");
- liczebnosc(tablica,tablica1);
- sort(tablica);
- puts("");
- puts("Tablica po wykonaniu sortowaniu:");
- wypisz(tablica);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement