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

Write a program that asks the user to enter the numbers from 1 to 16 (in any ord

ID: 3655075 • Letter: W

Question

Write a program that asks the user to enter the numbers from 1 to 16 (in any order) and then displays the numbers in a 4 by 4 arrangement, followed by the sums of the rows, columns and diagonals. The numbers in each column must be right aligned and separated by space(s). You must put all your code in the file input_output.c that is provided to you; do not modify the name or move it from its directory. Your output should match the example below (except that the input will be different for other executions!) User input is underlined.

Enter the numbers from 1 to 16 in any order, separated by spaces:
16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

Row sums: 34 34 34 34

Column sums: 34 34 34 34

Diagonal sums: 34 34

-------------------------------------------------------------------------------------------------------

I'm not sure on how to do this as my instructor hasn't shown much input/output examples. However, I think I might have the matrix output: (probably wrong)

int magic(matrix[], int i, int j)

printf("Enter the numbers from 1 to 16 in any order, separated by spaces: ");

scanf("%d", &matrix);

for(i=0;i<4;i++)

for(j=0;j<4;j++)

matrix[i][j];

Any help will be appreciated. Thank you!

Explanation / Answer

#include int main (void) { int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, num11, num12, num13, num14, num15, num16, row1, row2, row3, row4, col1, col2, col3, col4, diag1, diag2; #define sum 34; printf("Enter the numbers 1 to 16 in any order. "); scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &num1, &num2, &num3, &num4, &num5, &num6, &num7, &num8, &num9, &num10, &num11, &num12, &num13, &num14, &num15, &num16); printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, num11, num12, num13, num14, num15, num16); row1= num1+num2+num3+num4; row2= num5+num6+num7+num8; row3= num9+num10+num11+num12; row4= num13+num14+num15+num16; col1= num1+num5+num9+num13; col2= num2+num6+num10+num14; col3= num3+num7+num11+num15; col4= num4+num8+num13+num16; diag1= num1+num6+num11+num16; diag2= num4+num7+num10+num13; printf("Row sums: %d, %d, %d, %d ", row1, row2, row3, row4); printf("Column sums: %d, %d, %d, %d ", col1, col2, col3, col4); printf("Diagonal sums: %d, %d ", diag1, diag2); if(row1=sum && row2=sum && row3=sum && row4=sum && col1=sum && col2=sum && col3=sum && col4=sum && diag1=sum && diag2=sum) printf("Congratulations, these numbers form a magic square!"); else printf("Im sorry this is not a magic square."); getch (0); return (0); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote