hamaXD

Bubble OSHW2

Sep 3rd, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(){
  3.     int selection;
  4.     printf("Please select one of these options\n\n");//bug printf("Please select one of these options\n\n",a); not have a
  5.     printf("1) bubble sort\n");
  6.     printf("2) Quit\n");
  7.     scanf(" %d",&selection);
  8.    
  9.     switch(selection){
  10.         case 1 : Bubble(); break;
  11.         case 2 : break;
  12.         default: printf("Unkrow optins\n"); break;
  13.     }
  14.     printf("\n..Bye..\n");
  15.     return 0;
  16. }
  17. void Bubble(){
  18.     int input[5];
  19.     int temp,i,j,k;
  20.    
  21.     for(i=0;i<5;i++){ //fix -> for(i=0;i<=4;i++){ or for(i=0;i<5;i++){
  22.         printf("Please enter #%d: ",i+1);
  23.         scanf(" %d",&input[i]);
  24.     }
  25.    
  26.     for(i=0;i<4;i++){
  27.         for(j=i;j<5;j++){
  28.             if(input[j]< input[i]){
  29.                 temp = input[i];
  30.                 input[i]=input[j];
  31.                 input[j]=temp;
  32.             }
  33.         }
  34.     }
  35.     printf("The sorted list is: ");
  36.     for(i=0;i<=5;i++){
  37.         printf(" %d",input[i]);//bug  printf(" %d,input[i]");  input[i] must out side ""  
  38.     }
  39.     printf("\n");
  40. }
Add Comment
Please, Sign In to add comment