adiee

ooppr1

May 15th, 2021 (edited)
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void read(int [] ,int &);
  5. void display(int [],int );
  6. void myswap(int &,int &);
  7. void bsort(int [],int &n);
  8.  
  9. int main()
  10. {
  11. int n,arr[100];
  12. read(arr,n);
  13. display(arr,n);
  14. bsort(arr,n);
  15. display(arr,n);
  16. return 0;
  17. }
  18. //Function to read
  19. void read(int a[], int &n)
  20. {
  21.  
  22. cout<<"Enter number of elements in array: ";
  23. cin>>n;
  24. cout<<"Enter data :"<<endl;
  25. for(int i=0;i<n;i++)
  26. cin>>a[i];
  27. }
  28. //Function to display
  29. void display(int a[], int n)
  30. {
  31. cout<<endl<<"Array is..."<<endl;
  32. for(int i=0;i<n;i++)
  33. cout<<a[i]<<"\t";
  34. cout<<endl<<"---------------";
  35. }
  36.  
  37. void myswap(int &i,int &j)
  38. {
  39. int temp;
  40. temp=i;
  41. i=j;
  42. j=temp;
  43. }
  44.  
  45. void bsort(int a[],int &n)
  46. {
  47. for(int i=0;i<n;i++)
  48. {
  49. for(int j=1;j<n;j++)
  50. {
  51. if(a[j]<a[j-1])
  52. myswap(a[j],a[j-1]);
  53. }
  54. }
  55. }
  56.  
  57. ***OUTPUT***
  58.  
  59. Enter number of elements in array: 4
  60. Enter data :
  61. 34
  62. 54
  63. 12
  64. 43
  65.  
  66. Array is...
  67. 34 54 12 43
  68. ---------------
  69. Array is...
  70. 12 34 43 54
  71. ---------------
  72.  
Add Comment
Please, Sign In to add comment