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 8288749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:20:24+00:00 2026-06-08T12:20:24+00:00

I have tried making a program to sort numbers of an array. I have

  • 0

I have tried making a program to sort numbers of an array.

I have done my best but there is this problem: Although I do a loop to swap the numbers and arrange them, when I output the array, nothing changes and the array remains the same.

The code will make everything clearer

This is the main function:

int main(){
int arr[10];
//For loop to get from user numbers to be put into the array
for ( int i = 0; i<10; i++){
    cout << "Enter the number to be recorded: ";
    cin >> arr[i];
    cout << endl;
}
// Set counter n to 0 ( counts numbes of number swaps)
int n = 0;
do {
    //re sets counter to 0
    n=0;

    //Check the entire loop if arr[i] bigger than arr[i+1] and swaps their values if true then adds 1 to n
    for ( int i = 0; i>9; i++){
        if(arr[i]>arr[i+1]){
            swap(&arr[i], &arr[i+1]);//swaps by sending the addresses of the two array elements the pointers in the swap function
            n++;
        }
    }
}while(n>0); // if counter = 0 then end (therefore the numbers are arranged correctly since no swapping happened)
cout << "The numbers ordered are:\n\n";
// Loop to output the arranged array
for (int i =0; i<10; i++){
    cout << arr[i] << ", ";
}
cout<<endl;
system("PAUSE");
return 0;}

This is the swap function:

void swap ( int *p, int *t){
int temp;
temp = *p;
*p = *t;
*t = temp;}

I hope you guys can help me with my problem here and tell me what’s wrong with this code

Thank you all

  • 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-08T12:20:25+00:00Added an answer on June 8, 2026 at 12:20 pm

    Look closely at your for loop…its contents will never be executed.

    for ( int i = 0; i>9; i++){ ... }
    

    The condition i>9 should be i<9.

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

Sidebar

Related Questions

I have tried making a fiddle for this, but it's been too difficult to
I have tried searching over the internet about this problem but not able to
I have tried making every div 75px and the table within the div but
I don't know what I have been done. I am making a program. If
I have tried making (my first) a C# program: using System; using System.Collections.Generic; using
I am making a GUI in OpenGL (more specifically lwjgl). I have tried hard
I'm having trouble making python print out texts properly aligned. I have tried everything
Have tried to find solutions for this and can't really come up with anything.
I have tried this: #define format(f, ...) \ int size = strlen(f) + (sizeof((int[]){__VA_ARGS__})/sizeof(int))
I have tried many permutations but they all don't seems to work well. Am

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.