0% found this document useful (0 votes)
31 views

Lab Arrays 2D

This document outlines 9 exercises involving 2D arrays and matrices. The exercises include: 1) filling a 2D array with user input and displaying sum and average; 2) displaying row and column sums; 3) converting a 2D array to 1D; 4) calculating the product of two user-input matrices; 5) rotating a matrix 90 degrees clockwise; 6) searching an array for a value; 7) reversing an array using one or two arrays; 8) performing arithmetic operations on user-input values; and 9) generating a random number for a guessing game.

Uploaded by

Reda Belmir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lab Arrays 2D

This document outlines 9 exercises involving 2D arrays and matrices. The exercises include: 1) filling a 2D array with user input and displaying sum and average; 2) displaying row and column sums; 3) converting a 2D array to 1D; 4) calculating the product of two user-input matrices; 5) rotating a matrix 90 degrees clockwise; 6) searching an array for a value; 7) reversing an array using one or two arrays; 8) performing arithmetic operations on user-input values; and 9) generating a random number for a guessing game.

Uploaded by

Reda Belmir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 02: arrays 2D

EXERCISE 1
Write a program that fills a 2D array of size AxB whose values are entered through the
keyboard,
(maximum size 30x30) and displays the array as well as the sum and the average of all its
elements.

EXERCISE 2
Write a program that fills a 2D array of size AxB whose values are entered through the
keyboard,
(maximum size 30x30) and displays the array as well as the sum of each row and of each
column.

EXERCISE 3
Write a program that transforms a 2D array of 4 rows and 4 columns into a 1D array.
Example :

abcd
e f g h ------> a b c d e f g h i j k l m n o p
ijkl
mn o p

EXERCISE 4
Let 2 matrices of size n*m be entered by the user. (n and m are entered through the keyboard).
Write a program that calculates the product of the 2 matrices.
The 2 input matrices as well as the result of their product are to be displayed by the program.
EXERCISE 5
Write a program that rotates a matrix 90 degrees in a clockwise direction.
Example:

11 22 33
44 55 66
77 88 99

After rotation:
77 44 11
88 55 22
99 66 33

EXERCISE 6
Write a program that searches whether a value N entered through the keyboard exists in an
array of integers.

EXERCISE 7
Write a program that reverses the order of the elements of an array. To do using 2 different
methods :
1- Use the same array
2- The result is stored in another array
Random Exercises:
EXERCISE 8
Write a program asking the user to enter:
1-two values a and b, of type int ;
2-an op operator of type char, check that it is one of the following values: +, -, *, /.
Then, using a switch, display the result of the operation a op b.

EXERCISE 9
Write a program that generates a random integer between [0;20]
The user has 5 attempts to guess this number.
Use:

#include <time.h> // for random number generator seed

int randomNumber = 0;
time_t t;
// Initialization of random number generator
srand((unsigned) time(&t));
// get the random number
randomNumber = rand() % 21;

You might also like