Professional Documents
Culture Documents
C++ Quiz Spring22 Modela Sol
C++ Quiz Spring22 Modela Sol
Computer 1A
1. Finish writing a program which takes a matrix (2D array) and takes its transpose on
the same matrix (without creating a new array)
ie:
𝒂 𝒃 𝒄 𝑻 𝒂 𝒅 𝒈
[𝒅 𝒆 𝒇] = [𝒃 𝒆 𝒉]
𝒈 𝒉 𝒊 𝒄 𝒇 𝒊
void swap_func (int&x, int&y)
{
int temp = x;
x=y;
y=temp;
}
int main()
{
const int N_dim = 3;
int matA [N_dim][N_dim] = {1,2,3,4,5,6,7,8,9};
Page 1
int main( )
{
int k; int m=2;
for(k=2; k<=5; k++)
if( !fun(k, m))
cout<<" valid "<<k<<endl;
return 0;
}
Solution:
Page 2