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

  • SEARCH
  • Home
  • 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 7614887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:31:01+00:00 2026-05-31T02:31:01+00:00

I have this code so far, but the problem is that after the user

  • 0

I have this code so far, but the problem is that after the user enter 10 numbers, it wont sort the number in ascending or descending order

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>

    int main() 
   { 

   //variable declaration 
    int  iNumbers[10];
    int  iEntry=0;
    int  x=0;

    printf("Enter 10 numbers\n");


    for (x=0; x < 10; x++) {
        scanf("%d", &iNumbers[x]); //user for loop to scan every value in the array


    }

    printf("\n\nWhich order would you like to see your numbers?");
    printf("\n1)\tAscending\n");
    printf("\n2)\tDescending\n");
    scanf("%d", &iEntry); 

    switch(iEntry)  {
        case 1:
          printf("\n\n%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n\n",iNumbers[0],iNumbers[1],iNumbers[2]  ,iNumbers[3],iNumbers[4],iNumbers[5],iNumbers[6],iNumbers[7],iNumbers[8],iNumbers[9]);
        break; //prints all the numbers in the array in ascending order

        case 2:
           printf("\n\n%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n\n",iNumbers[9],iNumbers[8],iNumbers[7],iNumbers[6],iNumbers[5],iNumbers[4],iNumbers[3],iNumbers[2],iNumbers[1],iNumbers[0]);
        break; //prints all the numbers in the array in descending order
        }

        system("pause"); //pauses system
        return 0;
} //end of main function
  • 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-05-31T02:31:02+00:00Added an answer on May 31, 2026 at 2:31 am

    No, it won’t sort the number because you haven’t written the code to do it yet!

    Your code to print them out in forward or reverse order is okay, but it’s based solely on the order in which you input the numbers.

    If you want them sorted numerically rather than positionally, you need to either look into the qsort function (if you just want it sorted) or look into sort algorithms in general if you need to code up your own (such as homework).

    For an example of the latter, you can use the very simple pseudo-code below. It’s a bubble sort so not really suitable for serious use but it’s more than adequate for small data sets and/or homework:

    for i = 1 to length:
        for j = 1 to length -1:
            if array[j] > array[j+1]:
                temp = array[j]
                array[j] = array[j+1]
                array[j+1] = temp
    

    If, as you mention in a comment, you cannot use a bubble sort, you should google for one of the other sort algorithms and code it up.

    But I’d try to stick to those which are simple to understand. Next step up from bubble sort would probably be selection sort, pseudo-code below:

    for i = 1 to length-1:
        minidx = i
        for j = i+1 to length:
            if array[j] < array[minidx]:
                minidx = j
        if minidx != i:
            temp = array[i]
            array[i] = array[minidx]
            array[minidx] = temp
    

    This has the advantage of only swapping once per major pass rather than (possibly) many times. It does the minor pass only to find which index should be placed at a given position and then swaps.

    The only difference then between your two cases (ascending and descending) would be the use of > instead of < in the comparison function.

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

Sidebar

Related Questions

I have this code so far which perfectly but relies on there being a
This is what I have as far as code, it is in the first
I have this code in jQuery, that I want to reimplement with the prototype
I have this code that performs an ajax call and loads the results into
I have a datagrid that I want the user to sort the rows on.
I have this learning code I wrote for the morris seq in f# that
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);

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.