Question

The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It hasa=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf(Enter the %d th element of your array: \n,ii); s

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

#include <stdio.h>
#define N 4

// it should integer pointers as array is integer
void desc(int *a, int *b) {
   float tp;
   tp=*a;
   *a=*b;
   *b=tp;
}

int main() {

   int i, j, ii, mark[N] ;

   for (ii==0;ii<N;ii++) {
       printf("Enter the %d th element of your array: \n",ii);
       // we should have & to read values
       scanf("%d", &mark[ii]);
   }

   printf("You have entered the following array: \n");
   // ; missed in the loop
   for (ii=0;ii<N;ii++)
       printf("%d ", mark[ii]);
   printf("\n ");

   for(j=1; j < N; j++){
       for (i=0; i< N-j; i++)
           if ( mark[i]< mark[i+1])
               desc(&mark[i], &mark[i+1]);
       }
   printf("The descending order of the array is \n");
   for(i=0;i<N; i++)
   // we should not use & for printing
       printf("%d ", mark[i]);
   printf("\n");

   return 0;
}

1 2 #include <stdio.h> #define N 4 4 5 // it should integer pointers as array is integer void desc(int *a, int b) { float tp;

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
The following program sorts the array of numbers entered by the user and prints out the...
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
  • I'm trying to code a C program so it sorts an array of integer numbers of...

    I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...

  • Debug the following matrix program in C: // Program to read integers into a 3X3 matrix...

    Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) {         char size;         double Matrix[size][size+1];         printf("Enter 9 elements of the matrix:\n");         int i;         for (i = 0: i <= size: i++)     {       int j = 0;       for (; j <= size++; j++){         scanf("%d", matrix[i--][4])       }     }         Display(Matrix,9);         return 0; void...

  • #include "stdio.h" int main() { float array[5][3],rowsum=0.0,colsum=0.0; int i,j; for(i=0;i<5;i++){ printf("Enter the %d elements of array:\n",i);...

    #include "stdio.h" int main() { float array[5][3],rowsum=0.0,colsum=0.0; int i,j; for(i=0;i<5;i++){ printf("Enter the %d elements of array:\n",i); for(j=0;j<3;j++){ scanf("%f",&array[i][j]); } } printf("Given table data:\n"); for(i=0;i<5;i++){ for(j=0;j<3;j++){ printf(" %0.1f",array[i][j]); } printf("\n"); } for(i=0;i<5;i++){ for(j=0;j<3;j++){ rowsum=rowsum+array[i][j]; } printf("sum of the %d row is %0.1f\n",i,rowsum); rowsum=0; } for(j=0;j<3;j++){ colsum+=array[j][i]; printf("Sum of %d coloumn is %0.1f\n",j,colsum); colsum=0; } return(0); } can someone help me to get the correct row sum and column sum in c program

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

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

  • for c CHALLENGE ACTIVITY 9.7.1: Decrement array elements. Write a loop that subtracts 1 from each...

    for c CHALLENGE ACTIVITY 9.7.1: Decrement array elements. Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex lowerScores = {5,0,2,-3) becomes {4.0, 1.0). 1 include <stdio.h> 3 int main(void) 0 const int SCORES_SIZE - 4; int lowerScores [SCORES_SIZE]: int i; for (1 - 0; i < SCORES_SIZE; ++) { scanf("%d", &(lowerScores[i])); /" Your solution goes here / { 15 for (i = 0; i...

  • Trying to debug a C program given to me. This is what I was given... //...

    Trying to debug a C program given to me. This is what I was given... // Program to read numeric elements (including decimals) into a 3X3 matrix and display them #include<stdio.h> int main(void) {    int size = 3, Matrix[size][size];    printf("Enter 9 elements of the matrix:\n") for (int i = 0, i <=size, i++}        for (int j = 0, j <= size, i++)            scan("%c", Matrix1[2][2]);    diplay(Matrix) float display(int Matrix1[][], int size) (   ...

  • c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each...

    c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...

  • What is wrong with the following code that prints out the elements of a 2x3 array?...

    What is wrong with the following code that prints out the elements of a 2x3 array? for (int i 0; i < 3; ++i) { for (int j = 0; j < 2: ++j) { printf("x(%d] [%d] ". %.2f\n", i, j, x[i][j]); O Expression ali]li] is incorrect O There is nothing wrong with the code 0 %2t is invalid O It is printing for a 3x2 array

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