Write a program to sort one dimensional array in ascending order using non static method

Qu. Write a program to sort one dimensional array in ascending order using non static method.
Answer


  1. using System;
  2.  
  3. namespace Sort_Array
  4. {
  5. public class Program
  6. {
  7. public static void Main(string[] args)
  8. {
  9. int[] num= {22,50,11, 2, 49};
  10. Program p=new Program();
  11. p.SortArray(num);
  12. }
  13.  
  14. public void SortArray(int[] numarray)
  15. {
  16. int swap = 0;
  17. for(int i=0; i<numarray.Length; i++)
  18. {
  19. for(int j=i+1; j<numarray.Length; j++)
  20. {
  21. if(numarray[i]>=numarray[j])
  22. {
  23. swap=numarray[j];
  24. numarray[j]=numarray[i];
  25. numarray[i]=swap;
  26. }
  27. }
  28. Console.Write(numarray[i] + " ");
  29. }
  30. }
  31. }
  32. }
Output
2 11 22 49 50 _

More Example

Write A Program To Print One Dimensional Array In Reverse Order
Write A Program To Sort One Dimensional Array In Descending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Desending Order Static Class Array Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Static Method.
Write A Program To Add The Diagonal Of Two-Dimensional Array.
 

Share your thought