Full width home advertisement

HTML

Tech News

Ad

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int a[5]={30,10,-5,20,0},pass,i,temp,n=5;
  6. for(pass=0;pass<n-1;pass++){
  7. for(i=0;i<n-1;i++){
  8. printf("In \n");
  9. if(a[i]>a[i+1]){
  10. temp=a[i];
  11. a[i]=a[i+1];
  12. a[i+1]=temp;
  13. printf("shorted successfully\n");
  14. }
  15. }
  16.  
  17. }
  18. for(i=0;i<n;i++){
  19. printf("%d ",a[i]);
  20. }
  21. return 0;
  22. }

ALGORITHM


STEP 1:
    Read a[n]

STEP 2:
    Repeat for pass=1 to n-1 step by one
        Repeat for i=1 to n-1 step by one
            if(a[i]>[i+a])
                then
                    a[i]<-->a[i+1]
             end if
        end for i
    end for pass

STEP 3:
    Write [n];

Output

Bubble short in c


No comments:

Post a Comment

Bottom Ad [Post Page]