- Related Questions & Answers
- Place N^2 numbers in matrix such that every row has an equal sum in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
- Print all the combinations of N elements by changing sign such that their sum is divisible by M in C++
- C++ program to find the Sum of each Row and each Column of a Matrix
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Find maximum value of x such that n! % (k^x) = 0 in C++
- Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program
- Count of all possible values of X such that A % X = B in C++
- Print n x n spiral matrix using O(1) extra space in C Program.
- To print all elements in sorted order from row and column wise sorted matrix in Python
- Add N digits to A such that it is divisible by B after each addition in C++?
- Print N lines of numbers such that every pair among numbers has a GCD K
- Print first m multiples of n in C#
- Find a number x such that sum of x and its digits is equal to given n in C++
- Maximize the value of x + y + z such that ax + by + cz = n in C++

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

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 ’.

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

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

Advertisements