Sei sulla pagina 1di 7

Sana'a University

Faculty of Engineering
Mechatronics Department
Second Year

C Programming
Language

Arrays
HomeWork

Done by:
Osama Mohammed Mahyoub
(2017/162)
# This program prints the transpose of a matrix. It is obtained by
interchanging rows and columns of a matrix entered by the user.
This program can’t accept more than (5×5) matrix.

# Source Code:
# Output:
 Valid values:

[2] × [3]

[5] × [2]
 Invalid values:
When the number of rows or columns is more than 5, an error message
appears in the screen (Sorry! You can’t enter more than (5x5) matrix).

[5] × [8]

[9] × [6]
# Memory:
The entered values of the array are written and stored in the memory
over previous stored values, for example:
[3] × [2] matrix

Index Prvious value Index Next value


in[0][0] 54766257 in[0][0] 4

in[0][1] 8463655 in[0][1] 7

in[1][0] 27485654 in[1][0] 1

in[1][1] 65775467 in[1][1] 4

in[2][0] 3664562 in[2][0] 7

in[2][1] 5747786 in[2][1] 0

The same operation takes place when storing the values of “in[][]” array
into the new “out[][]” array but in reversed indices of i & j.
# Flowchart: start

int in[5][5] , out[5][5]


int row, col, i, j

Print “Enter number


of rows: ”

Read row

Print “Enter number


of columns: ”

Read col

False Is row <= 5


& col <= 5 ?

True
Print "\nSorry! You can't enter
i=1,j=1
more than (5x5) matrix."

end
False i <= row ?
i ++ , j++
j <= col ?

True

Print “Enter the


(i,j)th value: ”

Read in[i-1][j-1]

1
1

Print “Input is: “

i=0,j=0

False i < row ?


i ++ , j++
j < col ?

True
Print “in[i][j] \t”

Print “\n”

Print “Output is: “

i=0,j=0

False i < row ?


i ++ , j++
j < col ?

True
Print “in[j][i] \t”

Print “\n”
end
out[i][j]=in[j][i]

Potrebbero piacerti anche