SAMYAK99 / CS-180

Please leave a star ⭐ to support this project! ✨!!!. An Awesome beginner-friendly repo to help you in open-source contributions. Made specifically for contributions in HACKTOBERFEST 2022! .
https://www.youtube.com/watch?v=8xjmCsdgUhE
153 stars 398 forks source link

Create transpose vec.cpp #824

Closed SONIYAPATIDAR closed 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); }

SAMYAK99 commented 2 years ago

PR Accepted !! Please leave a star ⭐ to support this project! ✨!!!