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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:29:11+00:00 2026-06-11T18:29:11+00:00

My program so far creates an array based on a user’s declared size. The

  • 0

My program so far creates an array based on a user’s declared size. The program then fills that array with random numbers between 500 and 600 and prints the 4 of those numbers and creates a new line to continue printing them. Everything works fine up to this point. At the part where it is suppose to reprint the numbers in ascending order something goes wrong and it reprints only some of the numbers and not in any order. Any help on how to correct this is appreciated.

int main(){
            int size;
            int j, i;
        int temp;
        int a=0;
        double sum = 0;


        printf("Enter size of array ");
        scanf("%d", &size);


        int* array;
        array=malloc(size * sizeof(*array));
        int *aPtr = array;

        srand(time(NULL));
        for (i = 0; i < size; i++){
             aPtr[i] =(rand() % 101) + 500;
             printf("%d ", aPtr[i]);
             a++;
             if (a == 4){
            printf("\n");
            a = 0;
            }


      }
        printf("\n\n\nIn ascending order\n");
        for (i = 0; i< size; i++){
             for (j = 0; j < size; j++){
            if(aPtr[i] > aPtr[j]);
                temp=aPtr[i];
                aPtr[i]=aPtr[j];
                    aPtr[j]=temp;
                    }
                printf("%d\n", aPtr[i]);
            }
  • 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-11T18:29:12+00:00Added an answer on June 11, 2026 at 6:29 pm

    Problem was a result of the < sign, and the if statement not being in its own brackets. The second for loop for printing also helped print array correctly

     printf("\n\n\nIn ascending order\n");
            for (i = 0; i < size; i++){
                 for (j = i+1; j < size; j++){
                if(aPtr[i] > aPtr[j]){
                    temp=aPtr[i];
                    aPtr[i]=aPtr[j];
                        aPtr[j]=temp;
                }
                }
                }
                for (j = 0; j<size; j++)                
                printf("%d\n", aPtr[j]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Perl program that ran well on all Windows platforms so far.
I am trying to create an array of size n (where n is user's
I have a class that creates a static array of all properties, using a
First to tell you my issue: I have written a program that based on
I need to write a program, that will ask a user to enter a
I created a program which, so far, creates a binary tree of nodes for
I am trying to write a simple C program that creates directories (a mkdir
Here's my program so far: int main() { char choice = 'D'; string inputString;
So far to execute a Python program, I'm using > python file.py I want
My program's really consuming CPU time far more than I'd like (2 displays shoots

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.