Question

HOW DOES THE CODE WORK AND PLEASE TELL ME WHERE DID THE NUMBER [J] COME FROM...

HOW DOES THE CODE WORK AND PLEASE TELL ME WHERE DID THE NUMBER [J] COME FROM WHEN IT HASN'T BEEN DECLARED IN THE ABOVE STATEMENT

MOREOVER KINDLY ALSO DRY RUN THE PROGRAM TO MAKE IT MUCH EASIER TO UNDERSTAND
int main()
{

int i, j, a, n, number[i];
printf("Enter the value of N \n");
scanf("%d", &n);

printf("Enter the numbers \n");
for (i = 0; i < n; i++)
scanf("%d", &number[i]);

for (i = 0; i < n; ++i)
{

for (j = i + 1; j < n; j++)
{

if (number[i] > number[j])
{

a = number[i];
number[i] = number[j];
number[j] = a;

}

}

}

printf("The numbers arranged in ascending order are given below \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

int main()
{

int i, j, a, n, number[i];
printf("Enter the value of N \n");
scanf("%d", &n);

printf("Enter the numbers \n");
for (i = 0; i < n; i++)
scanf("%d", &number[i]);

for (i = 0; i < n; ++i)
{

for (j = i + 1; j < n; j++)
{

if (number[i] > number[j])
{

a = number[i];
number[i] = number[j];
number[j] = a;

}

}

}

printf("The numbers arranged in ascending order are given below \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);
return 0;
}

In the above code number[j] means the array element at the position j in the array number,where j = i+1

Suppose if i= 0 then j will be 1 (j = 0 + 1)

So,if( number[0] > number[1] ) is checked

Add a comment
Know the answer?
Add Answer to:
HOW DOES THE CODE WORK AND PLEASE TELL ME WHERE DID THE NUMBER [J] COME FROM...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include<stdio.h> int main() {       int data[10], i, j, temp;       printf("Enter 10 random number to...

    #include<stdio.h> int main() {       int data[10], i, j, temp;       printf("Enter 10 random number to sort in ascending order:\n");       for(i = 0; i < 10; i++)             scanf("%d", &data[i]);       /* Sorting process start */     ****** INSERT YOUR CODE TO COMPLETE THE PROGRAM ******       printf("After sort\n");       for(i = 0; i < 10; i++)             printf("%d\n",data[i]);       return 0; } Looking for alternative solutions for the program code.

  • Explain the following code, line by line. As well as the is going on over all....

    Explain the following code, line by line. As well as the is going on over all. #include <stdio.h> int main() {   int a[30];   int i,j,lasti;   int num;      lasti=0;   // scanf the number   scanf("%d",&a[0]);   while (1)   {   // sacnf the new number   printf("Enter another Number \n");   scanf("%d",&num);   for(i=0;i<=lasti;i=i+1)   {   printf("%d \n",a[i]);   // we check if the num that we eneterd is greter than i   if(a[i] > num)   {   for(j=lasti; j>= i;j--)   {   a[j+1]=a[j];   }      a[i]=num;   lasti++;   break;   }   }...

  • Hello, I need help with the following C code. This program asks the user to enter...

    Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...

  • C program-- the output is not right please help me to correct it. #include <stdio.h> int...

    C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...

  • **how can I make my program break if 0 is entered by user as last number...

    **how can I make my program break if 0 is entered by user as last number not always 10 numbers output should be enter 10 numbers:1 2 0 numbers entered by user are: 1 2 Largest number: 2 **arrays can ONLY be used in the main function, other than the main function pointers should be used #include #define N 10 void max(int a[], int n, int *max); int main (void) { int a [N], i , big; printf("enter %d numbers:",N);...

  • Convert the below C code to basic MIPS. The result of this code should ask for...

    Convert the below C code to basic MIPS. The result of this code should ask for two numbers to be inputed and give the answer. For example if 3 and 5 are inputed then the final answer should be as follows: 3&5=1, 3|5=7, 3^5=6, << = 12&20, >> = 0&1, and finally ~ = -4&-6. Please run the code yourself before you upload it to make sure it works. Start the code with .data. Thank you so much. #include <stdio.h>...

  • My code is giving me errors output enter numbers ending with 0: 1 2 4 3...

    My code is giving me errors output enter numbers ending with 0: 1 2 4 3 0 numbers entered by user are: 1 2 4 3 the max(largest) number is: 4 Use pointers. Arrays cannot be used except on the main function. #include #define N 10 void main() { int max,a[N]={0}; int getseries(*&a[N]); findmax(&a,N); } void getseries(int *p,int P) { int *q; printf("enter numbers ending with 0: "); for(q=p;q<=p+P;q++) { scanf("%d",q); if (*q=0) break; } } printf("numbers entered by user...

  • This should be done in C. I have the code written to where it gives me...

    This should be done in C. I have the code written to where it gives me the output however it is out of order from where it should be. The input should be 5 3 -7 3 5 -7 3 the output should be -7 occurs 2 times 3 occurs 3 times 5 occurs 2 times. My issue is I believe I need a bubble sort before my last loop but am unsure how to do it. #include <stdio.h> int...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • This code should exit in 0 is inputed or the code should repeat adding two number...

    This code should exit in 0 is inputed or the code should repeat adding two number if '1' is inputed. What are three logical or/and syntax errors in this code? int choice, numi, num2: Linn printf("Enter a number: "); scanf("%d", &numl); printf("Enter another number: "); scanf("%d", &num2); printf ("Their sum is d\n", (numl+num2)); printf ("Enter 1 to repeat, 0 to exit"); scanf("%d", &choice) } while (choice == 0) HH

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT