You are on page 1of 2

Cairo University First Year 2021/2022

Faculty of Engineering Quiz 1


Electronics & Comm. Dept. Spring 2022
Duration: 30 minutes

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};

for (int i=0; i<N_dim; i++)


for (int j=i+1; j<N_dim; j++)
swap_func (matA[i][j],matA[j][i]);
return 0;
}

2. Show the output of the following program

bool fun(int k, int i)


{
if( i >k/2)
return 0;
if(!( k%i))
return 1;
else
{
cout<<" i "<<i<<endl;
bool R = fun(k, i+1);
cout<<" k "<<k<<endl;
return R;
}
}

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

You might also like