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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:35:33+00:00 2026-06-14T07:35:33+00:00

I have the following source and when I execute it the values are getting

  • 0

I have the following source and when I execute it the values are getting their signs changed. I am not able to find out where I am going wrong. Any suggestions is helpful

Code

#include <stdio.h>
#include <stdlib.h>
int arrsort(int *arr, int size);
int display(int *arr, int size);

int main()
{
    int s_o_1=0, s_o_2=0;
    int i; //index for arrays
    int a[s_o_1],b[s_o_2];


    printf("enter the size of the first array\n");
    scanf("%d",&s_o_1);

    printf("Enter the values of the first array\n");
    for (i=0;i<s_o_1;i++)
    {
        scanf("%d",&a[i]);
    }

    printf("enter the size of the second array\n");
    scanf("%d",&s_o_2);

    printf("Enter the values of the second array\n");
    for (i=0;i<s_o_2;i++)
    {
        scanf("%d",&b[i]);
    }

    //sort the first array

    arrsort(a,s_o_1);
    printf("The sorted first array is\n");
    display(a,s_o_1);

    //sort the second array

    arrsort(b,s_o_2);
    printf("The sorted second array is\n");
    display(b,s_o_2);

}

int arrsort(int *arr, int size)
{
    int temp; //for holding the temp value
    int i; //for indexing
    int j;

    for(j=0;j<size;j++)
    {
        for(i=0;i<size;i++)
        {
            if(arr[i]>arr[i+1])
            {
            temp=arr[i];
            arr[i]=arr[i+1];
            arr[i+1]=temp;
            }
        }   
    }
}



int display(int *arr, int size)
{
    int i; //array index
    for (i=0;i<size;i++)
    {
        printf("%d\t",i);

    }
    printf("\n");
    for (i=0;i<size;i++)
    {
        printf("%d\t",arr[i]);
    }
    printf("\n");
}

Output

enter the size of the first array
5
Enter the values of the first array
1 5 -10 -15 3
enter the size of the second array
5
Enter the values of the second array
-3 -5 15 9 10
The sorted first array is
0   1   2   3   4   
-15 -10 3   5   10  
The sorted second array is
0   1   2   3   4   
-15 -10 -5  -3  9   
  • 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-14T07:35:34+00:00Added an answer on June 14, 2026 at 7:35 am

    The problem is the array declaration:

    int s_o_1=0, s_o_2=0;
    int i; //index for arrays
    int a[s_o_1],b[s_o_2];
    

    The arrays are probably declared with size 0. Either declare with an appropriate maximum size, or declare after reading the sizes for the arrays.

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

Sidebar

Related Questions

I have the following code fragment but when I execute it is not printing
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record
I have the following source code: Processmethod() { QDialog *ProcessMessage = new QDialog; Ui::DialogProcessMessage
I have the following source code: void Processmethod() { QDialog *ProcessMessage = new QDialog;
I have the following XML source structure: <turnovers> <turnover repid=1 amount=500 rate=0.1/> <turnover repid=5
I have the following SVG source code that generates a number of boxes with
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }
I have the following in my .screenrc source ~/bin/Screen/multiUserSettings It gives me No such
I have the following lines in my .zshrc source /etc/profile source $HOME/.profile My .profile
I have the following question. I have a set of Fortran90 source files, most

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.