#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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education