Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:15:09+00:00 2026-06-14T22:15:09+00:00

I am currently trying to create an array and display it reverse or descending

  • 0

I am currently trying to create an array and display it reverse or descending order. It currently displays a list of numbers but sometimes it does not follow the correct descending order. I believe the issues is in the if statement in between the two for loops, each time I am comparing a random number between 1-101 with the first number in your array. Instead of doing it that way, How can I compare the numbers in the array with each other? Or any suggestion in proving my reverse order array generator?

CODE

namespace reverseArray
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        long operations = 0;
        int size;
        int max;
        int[] createArray;
        int[] sortArray;
        int[] copyArray;

public void ReverseOrder()
        {
            size = Convert.ToInt32(textBoxSize.Text);
            max = Convert.ToInt32(textBoxMax.Text);
            createArray = new int[size];
            copyArray = new int[size];
            sortArray = new int[size];

            createArray[size - 1] = 1;

            for (int i = size - 1; i > 0; i--)
            {
                createArray[i - 1] = createArray[i] + r.Next(1, max);
            }

            for (int i = size - 1; i > 0; i--)
            {
                if (r.Next(1, 101) < createArray[0])
                {
                    for (int x = size - 1; x > 0; x--)
                    {
                        createArray[x] = r.Next(1, createArray[0]);
                    }
                }
            }

        }


private void buttonCreateArray_Click(object sender, EventArgs e)
        {

ReverseOrder();

}

}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:15:10+00:00Added an answer on June 14, 2026 at 10:15 pm

    Use LINQ

    using System.Linq;
    
    namespace reverseArray
    {
            public partial class Form1 : Form
            {
                public Form1()
                {
                    InitializeComponent();
                }
                long operations = 0;
                int size;
                int max;
                int[] createArray;
                int[] orderedArray;
                int[] orderedByDescendingArray;    
    
                public int[] CreateArray(int size, int max)
                {
                    var result = new int[size];
                    Random r = new Random();
                    for(int i; i<size; i++)
                    {
                       result[i] = r.Next(max);
                    }
                    return result;
                }
    
    
                private void buttonCreateArray_Click(object sender, EventArgs e)
                {
                    size = Convert.ToInt32(textBoxSize.Text);
                    max = Convert.ToInt32(textBoxMax.Text);
    
                    createArray = CreateArray(size, max);
                    orderedArray = array.OrderBy(a => a);
                    orderedByDescendingArray = array.OrderByDescending(a => a);        
               }
          }
    }
    

    //P.S. Code may contain errors coz I typed it directly here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to create a subclass of UIImageView in order to make it
I'm currently trying to create a T-SQL, which runs through a list of deliveries
I'm trying to display an array in a random order in a foreach loop
I am currently trying to display a RSS feed in a PHP page, but
I'm trying to create a dynamic array in my List class that will start
I am currently trying to pass an array that I have created in Javascript
I'm currently trying to create a template in TextMate. The template is very basic:
I'm currently trying to create an email application using Rails and Sendgrid. This application
I'm currently trying to create a program that estimates location based on signal strength.
I am currently trying to create a function which will allow me to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.