#include <stdio.h>    int main() {        int x[a][w];        int  k, l, n, tmp;               printf("Enter the order of the array:");        scanf("%d", &n);                printf("Enter your entries for the input mat:\n");        for (i = 0; i < n; i++) {                for (j = 0; j < n; j++) {                        scanf("%d", &mat[i][j]);                }        }           /* sort the contents of the two dimensional array */         for (i = 0; i < n; i++) {                 for (j = 0; j < n; j++) {                         tmp = x[i][j];                         l = j + 1;                         for (k = i; k < n; k++) {                                                                         l++;                                 }                                 l = 0;                         }                 }         }           /* print the result */         printf("\n");         printf("Resultant array:\n");         for (i = 0; i < n; i++) {                 for (j = 0; j < n; j++) {                         printf("%d ", mat[i][j]);                 }                 printf("\n");         }         getch ( );   }          please fix the code thanks :)   input :    How many column number :  4 how many row number: 5   generated number:    3 9 6 7  1 7 9 0   3 2 5 6  2 1 4 6 2 1 3 4   sorted :  3 6 7 9 0 1 7 9   2 3 5 6 1 2 4 6 1 2 3 4

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 1PP: (Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard...
icon
Related questions
Question
#include <stdio.h>
  

  int main() {
        int x[a][w];
        int  k, l, n, tmp;

       
        printf("Enter the order of the array:");
        scanf("%d", &n);

        
        printf("Enter your entries for the input mat:\n");
        for (i = 0; i < n; i++) {
                for (j = 0; j < n; j++) {
                        scanf("%d", &mat[i][j]);
                }
        }
 
        /* sort the contents of the two dimensional array */
        for (i = 0; i < n; i++) {
                for (j = 0; j < n; j++) {
                        tmp = x[i][j];
                        l = j + 1;
                        for (k = i; k < n; k++) {
                               
                                        l++;
                                }
                                l = 0;
                        }
                }
        }
 
        /* print the result */
        printf("\n");
        printf("Resultant array:\n");
        for (i = 0; i < n; i++) {
                for (j = 0; j < n; j++) {
                        printf("%d ", mat[i][j]);
                }
                printf("\n");
        }
        getch ( );
  }
 
 
 
 
 please fix the code thanks :)
 
input : 
 
How many column number :  4
how many row number: 5
 
generated number: 
 
3 9 6 7 
1 7 9 0 
 3 2 5 6 
2 1 4 6
2 1 3 4
 
sorted :
 3 6 7 9
0 1 7 9 
 2 3 5 6
1 2 4 6
1 2 3 4
Expert Solution
Changes made
  • Declared variables 'a' and 'w' as constant of type integers with size 100.
  • A prompt asking user to enter the desired size of array.
  • Input the array in variable 'x' and not an undeclared variable 'mat'.
  • For sorting only two loops were used which is correct for 1 dimensional array but not for 2 dimensional array, therefore used 3 loops for sorting the array.
Program

#include <stdio.h>
#include <windows.h>

const int a = 100;
const int w = 100;

int main () {
 
 int x[a][w],mb[a][w];
 
 int i,j,k,m,n;
 
  int temp;
  
 printf ("Enter the order of the matrix \n");
 
 scanf ("%d %d", &m,&n);
 
 printf ("Enter elements of the matrix \n");
 
 for (i=0;i<m;++i) {
 
  for (j=0;j<n;++j) {
 
   scanf ("%d",&x[i][j]);
 
   mb[i][j] = x[i][j];
 
  }
 
 }
 
 printf ("The given matrix is \n");
 
 for (i=0;i<m;++i) {
 
  for (j=0;j<n;++j) {
 
   printf (" %d",x[i][j]);
 
  }
 
  printf ("\n");
 
 }
 
 printf ("After soring the array in ascending order\n");
 
 for (i=0;i<m;++i) {
 
  for (j=0;j<n;++j) {
 
   for (k=(j+1);k<n;++k) {
 
    if (x[i][j] > x[i][k]) {
 
     temp = x[i][j];
 
     x[i][j] = x[i][k];
 
     x[i][k] = temp;
 
    }
 
   }
 
  }
 
 }
 
 /* End of outer for loop*/
 
 for (i=0;i<m;++i) {
 
  for (j=0;j<n;++j) {
 
   printf (" %d",x[i][j]);
 
  }
 
  printf ("\n");
 
 }
 

 system("pause");
 return 0;
 
}

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr