0% found this document useful (0 votes)
3 views2 pages

C Post Lab08

The document outlines a structured programming lab exercise for students, focusing on the manipulation of a 2D array in C. It includes tasks such as filling a 3x3 integer array, computing sums of rows, columns, and diagonals, checking for magic squares, counting even numbers, searching for prime numbers, and sorting diagonal elements. Students are required to implement various functions to achieve these objectives and display the results in a tabular format.

Uploaded by

saw20219009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

C Post Lab08

The document outlines a structured programming lab exercise for students, focusing on the manipulation of a 2D array in C. It includes tasks such as filling a 3x3 integer array, computing sums of rows, columns, and diagonals, checking for magic squares, counting even numbers, searching for prime numbers, and sorting diagonal elements. Students are required to implement various functions to achieve these objectives and display the results in a tabular format.

Uploaded by

saw20219009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

King Hussein Faculty of Computing Sciences

Department of Computer Science

Structured Programming Lab


Post-Lab #8 – 2D array

Post-Lab #8 Exercises
Student Name
Student University ID
Date

Exercise #1

Develop a C program to perform the following:


o Create a 3 x 3 2-D integer array named square.
o Fill the array with the following numbers:

10 17 12
15 13 11
14 9 16

o Compute and print the sum of each row and each column.
o Compute and print the sum of the main and secondary diagonals’ elements.
o Swap the elements of the main and secondary diagonals.
o Pass the square array to a function named magic, which checks and returns a result to
indicate that the passed square is a magic square or not. A Magic Square is the square in
which the sum of all its rows, columns, and diagonals (Main and secondary diagonals) is the
same.
o Pass the square array to a function named countEven, which counts and returns the
number of even numbers in the array.
o Pass the square array to a function named searchPrime, which searches for and returns
the first prime number in the array. If the array doesn’t contain a prime number, it
returns 0. The main function prints the result.
o Reprint the square array in a tabular format.
o Create a 1-D 3-elements array named diagonal.
o Fill diagonal array with the elements in the diagonal of the square array.
o Pass diagonal array to a function named sort, which sorts the array elements in
descending order.

You might also like