PROGRAM TO SORT ARRAY ELEMENTS (BUBBLE SORT)

  1. C++ PROGRAM TO SORT ARRAY ELEMENTS  (BUBBLE SORT

  2. #include<conio.h>
  3. #include<iostream.h>
  4. void main()
  5. {
  6. clrscr();
  7. int a[100],i,n,j,temp;
  8. cout<<"How many element: ";
  9. cin>>n;
  10. cout<<"Enter the elements of array: "<<endl;
  11. for(i=0;i<n;i++)
  12. cin>>a[i];
  13. cout<<"The elements of array Before Sorting: "<<endl;
  14. //Coding by: Mohamed safeer
  15. //WWW.4CSSSM.BLOGSPOT.COM
  16. for(i=0;i<n;i++)
  17. cout<<a[i]<<" ";
  18. cout<<endl;
  19. for(i=0;i<n;i++)
  20. {
  21. for(j=0;j<n-1-i;j++)
  22. {
  23. if(a[j]>a[j+1])
  24. {
  25. temp=a[j];
  26. a[j]=a[j+1];
  27. a[j+1]=temp;
  28. }
  29. }
  30. }
  31. cout<<"Elements of array After Sorting: "<<endl;
  32. for(i=0;i<n;i++)
  33. cout<<a[i]<<" ";
  34. getch();
  35. }

Comments

Popular posts from this blog