Print an N x M matrix such that each row and column has all the vowels in it | C ++ implementation of the approach ; Function to print the required matrix ; Impossible to generate the required matrix ; Store all the vowels ; Print the matrix ; Print vowels for every index ; Shift the vowels by one ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printMatrix ( int n , int m ) { if ( n < 5 m < 5 ) { cout << -1 ; return ; } string s = " aeiou " ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { cout << s [ j % 5 ] << " ▁ " ; } cout << endl ; char c = s [ 0 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { s [ i ] = s [ i + 1 ] ; } s [ 4 ] = c ; } } int main ( ) { int n = 5 , m = 5 ; printMatrix ( n , m ) ; return 0 ; }