- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Print an N x M matrix such that each row and column has all the vowels in it in C++

In this problem, we have to create a 2D matrix of size n X m. And in this matrix, we have to place only vowels in such a way that each row and column has all vowels in it.

All vowels mean all a, e, i, o, u are present in each row and each column of the matrix. This makes the minimum number of rows and columns required is 5 i.e. the smallest matrix is of the size 5X5.

Let’s take an example to understand the topic better

**Example 1 **−

Input : N = 5 and M = 5. Output : a e i o u e i o u a i o u a e o u a e i u a e i o

**Explanation** − In sequence, the vowels a e i o u are arranged in every row and column. The first row with be **aeiou**, the next will start with e being eioua and next will be **iouae**.

**Example 2** −

Input : N = 3 M = 4 Output : Matrix cannot be created.

**Explanation** − minimum value for N and M is 5.

To solve this problem, we first condition that the minimum number of elements in 5 i.e., if value less than 5 is provided in the input “matrix,** cannot be created**” is printed. Otherwise, we will print the sequence ‘ aeiou ’ in a repeated form. With an array, the sequence to be printed is changed by rotating it one step left making in ‘ eioua ’, then ‘ iouae ’.

## Example

#include <iostream> using namespace std; void vowelMatrix(int n, int m) { if (n<5||m<5) { cout<<"Marix cannot be created!"; return; } string s = "aeiou"; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout<<s[(j+i) % 5]<<" "; } cout << endl; } } int main(){ int n = 5, m = 5; vowelMatrix(n, m); return 0; }

## Output

a e i o u e i o u a i o u a e o u a e i u a e i o

- Related Questions & Answers
- Place N^2 numbers in matrix such that every row has an equal sum in C++
- Program to find number m such that it has n number of 0s at end in Python
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Print all the combinations of N elements by changing sign such that their sum is divisible by M in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
- Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program
- How to find the row sum for each column by row name in an R matrix?
- Print N lines of numbers such that every pair among numbers has a GCD K
- How to find the row that has maximum number of duplicates in an R matrix?
- Find the column number with largest value for each row in an R matrix.
- To print all elements in sorted order from row and column wise sorted matrix in Python
- Find maximum value of x such that n! % (k^x) = 0 in C++
- C++ program to find the Sum of each Row and each Column of a Matrix
- Add N digits to A such that it is divisible by B after each addition?
- How to find the row products for each row in an R matrix?