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;   }   }...

  • 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);...

  • 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...

  • 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

  • Help with my code: The code is suppose to read a text file and when u...

    Help with my code: The code is suppose to read a text file and when u enter the winning lotto number it suppose to show the winner without the user typing in the other text file please help cause when i enter the number the code just end without displaying the other text file #include <stdio.h> #include <stdlib.h> typedef struct KnightsBallLottoPlayer{ char firstName[20]; char lastName[20]; int numbers[6]; }KBLottoPlayer; int main(){ //Declare Variables FILE *fp; int i,j,n,k; fp = fopen("KnightsBall.in","r"); //...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • Finish the code below (using bubble sort) to sort the datafile in ascending order. each number...

    Finish the code below (using bubble sort) to sort the datafile in ascending order. each number should stop after "t" #include #include #include int main() { char letter[1400]; int length; FILE *fptr; if ((fptr = fopen("datafile1.txt","r")) == NULL) { printf("Error! opening file"); return (1); } if (fgets(letter,5000,fptr) != NULL) { printf("The string is in the file is\n\n"); puts(letter); } fclose(fptr); printf("\n\n"); length = strlen(letter); sortascending(length,letter); puts(letter); return 0; } ***datafile1.txt*** 1804289383t846930886t681692777t1714636915t1957747793tn424238335t719885386t1649760492t596516649t1189641421tn1025202362t1350490027t783368690t1102520059t2044897763tn1967513926t1365180540t1540383426t304089172t1303455736tn35005211t521595368t294702567t1726956429t336465782tn861021530t278722862t233665123t2145174067t468703135tn1101513929t1801979802t1315634022t635723058t1369133069tn1125898167t1059961393t2089018456t628175011t1656478042tn1131176229t1653377373t859484421t1914544919t608413784tn756898537t1734575198t1973594324t149798315t2038664370tn1129566413t184803526t412776091t1424268980t1911759956tn749241873t137806862t42999170t982906996t135497281tn511702305t2084420925t1937477084t1827336327t572660336tn1159126505t805750846t1632621729t1100661313t1433925857tn1141616124t84353895t939819582t2001100545t1998898814tn1548233367t610515434t1585990364t1374344043t760313750tn1477171087t356426808t945117276t1889947178t1780695788tn709393584t491705403t1918502651t752392754t1474612399tn2053999932t1264095060t1411549676t1843993368t943947739tn1984210012t855636226t1749698586t1469348094t1956297539tn update** I'm supposed to write a code that scans...

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
ADVERTISEMENT