none
How to arrange the the number like this output RRS feed

  • Question

  • hello,

    int[]  inputarr = {1,2,3,4,5,6,7,8,9,10}

    I am beginner please help me, how to arrange array list same as the output.

    output should be like this : 10,9,8,4,5,67,3,2,1.

    is it possible by using linq or any other option.


    Friday, September 20, 2019 4:03 PM

Answers

  • Here is a simple solution

    int[] inputarr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    First of all would like say thank you for the responded on my post,

    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));

    if we execute this statement  ,

    output will in reverse order, but i don't want like that.

    i want output should be,

    10,9,8,4,5,6,7,3,2,1 

    Well then looking at what is desired there is nothing I can provide that logically produce this result. My first reply of course is not a desired result and the next thought would be to order and sort via odd/even numbers which is incorrect also so you need to indicate how this pattern is formulated.

    Bottom line is a practically written formula is required to move forward.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JonPaker Saturday, September 21, 2019 5:45 PM
    Saturday, September 21, 2019 12:55 PM
    Moderator

All replies

  • Here is a simple solution

    int[] inputarr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, September 20, 2019 4:32 PM
    Moderator
  • Here is a simple solution

    int[] inputarr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    First of all would like say thank you for the responded on my post,

    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));

    if we execute this statement  ,

    output will in reverse order, but i don't want like that.

    i want output should be,

    10,9,8,4,5,6,7,3,2,1 

    Saturday, September 21, 2019 2:50 AM
  • In order to find a solution for different arrays, show the problem formulation.

    Saturday, September 21, 2019 11:34 AM
  • Here is a simple solution

    int[] inputarr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    First of all would like say thank you for the responded on my post,

    Array.Reverse(inputarr);
    Console.WriteLine(string.Join(",",inputarr));

    if we execute this statement  ,

    output will in reverse order, but i don't want like that.

    i want output should be,

    10,9,8,4,5,6,7,3,2,1 

    Well then looking at what is desired there is nothing I can provide that logically produce this result. My first reply of course is not a desired result and the next thought would be to order and sort via odd/even numbers which is incorrect also so you need to indicate how this pattern is formulated.

    Bottom line is a practically written formula is required to move forward.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JonPaker Saturday, September 21, 2019 5:45 PM
    Saturday, September 21, 2019 12:55 PM
    Moderator
  • I tried to apply that kind of logic below inserted the codes .

    i am not sure is it the right way or not ,

    please suggest me.

           static void Main(string[] args)
            {
                int[] inputArr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                int[] result = new int[10];
                for (int i = 0; i < inputArr.Length; i++)
                {
                    if (i < 3)
                    {
                        result[i] = 10 - i;
                    }
                    if (i > 2 && i < 7)
                    {
                        result[i] = i + 1;
                    }
    
                    if (i>= 7)
                    {
                        result[i] = i - 6;
                    }
    
                }
                foreach (var items in result)
                {
                    Console.Write(string.Join(",", items));
                }
    
                Console.ReadKey();
            }

    Sunday, September 22, 2019 5:26 AM