Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C (NOT C++) program as follows (please don\'t use pointers): 1. Ask the

ID: 3798295 • Letter: C

Question

Create a C (NOT C++) program as follows (please don't use pointers):

1. Ask the user for the name of a file, read the name of the file from standard input. The first row of the file contains the number of rows and columns in the file. The remainder of the file is expected to contain a matrix of numbers in the form of multiple lines of space or tab delimited numbers. Examples are provided below. For this project, no valid input file shall have more then 20 rows or 20 columns.

2. Read the contents of the file and determine if the matrix of numbers exhibits “vertical additive symmetry”. The definition of this term is provided below.

3. If the matrix of numbers in the file exhibits “vertical additive symmetry”, output “vertical additive symmetry” to standard output. Otherwise, output “no vertical additive symmetry” to standard output.

4. Print each row of the matrix in descending order, one row per line of output, with each number separated by a space.

Definition of vertical additive symmetry: A matrix of numbers is defined to exhibit vertical additive symmetry if the sum of the numbers in the columns of the matrix exhibits vertical symmetry.

Explanation / Answer

Here is the code for you:

#include <stdio.h>
int main()
{
FILE *fp;
char fileName[30];
printf("Enter the name of the file to read from: ");
scanf("%s", fileName);
fp = fopen(fileName, "r");
int rows, cols;
fscanf(fp, "%d%d", &rows, &cols);
int array[rows][cols];
for(int i = 0; i < rows; i++)
for(int j = 0; j < cols; j++)
fscanf(fp, "%d", &array[i][j]);
  
int colSums[cols];
for(int i = 0; i < cols; i++)
colSums[i] = 0;
for(int i = 0; i < rows; i++)
for(int j = 0; j < cols; j++)
colSums[j] += array[i][j];
int verticalSymmetry = 1;
for(int i = 0; i < cols-1; i++)
if(colSums[i] != colSums[i+1])
verticalSymmetry = 0;
if(verticalSymmetry)
printf("vertical additive symmetry ");
else
printf("no vertical additive symmetry ");
  
  
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols-1; j++)
for(int k = 0; k < cols-j-1; k++)
if(array[i][k] < array[i][k+1])
{
int temp = array[i][k];
array[i][k] = array[i][k+1];
array[i][k+1] = temp;
}
}

for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
printf("%d   ", array[i][j]);
printf(" ");
}
  
}