asmodeus94

sortowanieBabelkowe

Feb 12th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int tab[10];
  5. void wys(){
  6.      for(int i=0;i<10;i++){
  7.         cout<<"["<<tab[i]<<"] ";
  8. }
  9. getchar();getchar();
  10. }
  11. void sortujB(){
  12. int j;
  13.      for(int i=9;i>0;i--){
  14.               for(j=0;j<i;j++){
  15.                  if(tab[j]>tab[j+1]) swap(tab[j],tab[j+1]);
  16.               }
  17.      }
  18. }
  19. void los(){
  20. srand(time(NULL));
  21. for(int i=0;i<10;i++){
  22.         tab[i]=rand()%10;      
  23. }
  24. }
  25. int main(){
  26. int wybor;          
  27. do{
  28. system("cls");
  29. cout<<"x=1 - wyswietl tablice\n";
  30. cout<<"x=2 - losuj\n";
  31. cout<<"x=3 - sortuj babelkowo\n";
  32. cout<<"x=4 - wyjscie\n";
  33. cout<<"Wybor: ";
  34. cin>>wybor;
  35. switch(wybor){
  36. case 1:{wys();break;}
  37. case 2:{los();break;}
  38. case 3:{sortujB();break;}
  39. }}while(wybor!=4);            
  40. }
Advertisement
Add Comment
Please, Sign In to add comment