monuverma1501 / HactoberFest2022

#Hacktoberfest
9 stars 114 forks source link

Create transpose.cpp #148

Open SONIYAPATIDAR opened 2 years ago

SONIYAPATIDAR commented 2 years ago

include

include

using namespace std;

void transpose(vector<vector>vec){

for(int i=0;i<vec.size();i++){
    for (int j=0;j<i;j++){
        int a = vec[i][j];
        vec[i][j]=vec[j][i];
        vec[j][i]=a;

    }
}
for (int i=0;i<vec.size();i++){
        for (int j=0;j<vec.size();j++){
                cout<<vec[i][j]<<" ";
        }
        cout<<endl;
}

}

int main(){ vector<vector>vec ={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; for (int i=0;i<vec.size();i++){ for (int j=0;j<vec.size();j++){ cout<<vec[i][j]<<" "; } cout<<endl; } cout<<endl; transpose(vec); }