The number of words which can be formed with 2 different consonants

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Given four integers X, Y, M and N. The task is to find the number of ways to form a word by choosing X number of vowels and Y number of consonants from total numbers of M vowels and N consonants.
    Examples: 
     

    Input : X = 2, Y = 2, M = 3, N = 3 
    Output : 216 
    The total number of ways of choosing 2 vowels from a total number of 3 vowels is 

    The number of words which can be formed with 2 different consonants
    i.e 3 
    The total number of ways of choosing 2 consonants from a total number of 3 consonants is 
    The number of words which can be formed with 2 different consonants
    i.e 3. 
    The total number of ways of selecting 2 consonants from 3 and 2 vowels from 3 is 
    The number of words which can be formed with 2 different consonants
    The number of words which can be formed with 2 different consonants
    = 9 
    The total number of ways of arranging 4 letters among themselves = 4! = 24 
    Hence, the required number of ways = 24 * 9 = 216
    Input : X = 1, Y = 2, M = 2, N = 3 
    Output : 36 
     

    Recommended: Please try your approach on {IDE} first, before moving on to the solution.
    Approach : 
     

    Below is the implementation of the above approach: 
     

    C++

    #include <bits/stdc++.h>

    using namespace std;

    int fact(int n)

    {

        int res = 1;

        for (int i = 2; i <= n; i++)

            res = res * i;

        return res;

    }

    int nCr(int n, int r)

    {

        return fact(n) / (fact(r) * fact(n - r));

    }

    int NumberOfWays(int X, int Y, int M, int N)

    {

        return fact(X + Y) * nCr(M, X) * nCr(N, Y);

    }

    int main()

    {

        int X = 2, Y = 2, M = 3, N = 3;

        cout << NumberOfWays(X, Y, M, N);

        return 0;

    }

    Java

    import java.util.*;

    import java.lang.*;

    import java.io.*;

    class GFG

    {

        static int fact(int n)

        {

            int res = 1;

            for (int i = 2; i <= n; i++)

                res = res * i;

            return res;

        }

        static int nCr(int n, int r)

        {

            return fact(n) / (fact(r) *

                              fact(n - r));

        }

        static int NumberOfWays(int X, int Y,

                                int M, int N)

        {

            return fact(X + Y) * nCr(M, X) *

                                 nCr(N, Y);

        }

        public static void main (String[] args)

                      throws java.lang.Exception

        {

            int X = 2, Y = 2, M = 3, N = 3;

            System.out.println(NumberOfWays(X, Y, M, N));        

        }

    }

    Python3

    def fact(n):

        res = 1

        for i in range(2, n + 1, 1):

            res = res * i

        return res

    def nCr(n, r):

        return fact(n) // (fact(r) * fact(n - r))

    def NumberOfWays(X, Y, M, N):

        return fact(X + Y) * nCr(M, X) * nCr(N, Y)

    if __name__ == '__main__':

        X = 2

        Y = 2

        M = 3

        N = 3

        print(NumberOfWays(X, Y, M, N))

    C#

    using System;

    class GFG

    {

        static int fact(int n)

        {

            int res = 1;

            for (int i = 2; i <= n; i++)

                res = res * i;

            return res;

        }

        static int nCr(int n, int r)

        {

            return fact(n) / (fact(r) *

                              fact(n - r));

        }

        static int NumberOfWays(int X, int Y,

                                int M, int N)

        {

            return fact(X + Y) * nCr(M, X) *

                                 nCr(N, Y);

        }

        public static void Main (String[] args)

        {

            int X = 2, Y = 2, M = 3, N = 3;

            Console.WriteLine(NumberOfWays(X, Y, M, N));        

        }

    }

    Javascript

    <script>

          function fact(n) {

            var res = 1;

            for (var i = 2; i <= n; i++)

                res = res * i;

            return res;

          }

          function nCr(n, r) {

            return fact(n) / (fact(r) * fact(n - r));

          }

          function NumberOfWays(X, Y, M, N) {

            return fact(X + Y) * nCr(M, X) * nCr(N, Y);

          }

          var X = 2,

            Y = 2,

            M = 3,

            N = 3;

          document.write(NumberOfWays(X, Y, M, N));

        </script>

    Time Complexity: O(n), time to calculate factorial of n
    Auxiliary Space: O(1), as no extra space is required


    What is a word with 2 consonants?

    A double consonant is a consonant letter occurring twice in succession in a word. For example, the 'nn' in tunnel is a double consonant. Double consonants are frequently found in words that have a suffix added to them, for example 'beginning'. To spot another example, is 'happy' a double consonant?

    How many words are formed by 2 vowels and 3 consonants?

    =60×120=7200.

    Do consonants have 2 sounds?

    The letters are divided into two groups, consonants and vowels. The vowels are the letters A, E, I, O, and U. All the rest are consonants. Consonants usually have one sound, but vowels have two sounds, a short and a long sound.

    How many words consist of 2 consonants and 2 vowels?

    "Number of words each consisting of two vowels and two consonants which can be made out of the\netters of the word 'DEVASTATION is\nA) 126" Was this answer helpful?