Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C++ to given two integers k and n, your program determines th

ID: 3731386 • Letter: W

Question

Write a program in C++ to given two integers k and n, your program determines the maximum number of k by n matrices with the following constraints.

The matrices contain only 0s and 1s.

The matrices may not contain any column of all zero values.

Input Format

Two integer values n and k read from console.

Constraints

n>0 k>0

Output Format

A single integer value displayed on console.

Sample Input 0

Sample Output 0

Explanation 0

For the input with n=2 and k=2, we may have 9 matrices satisfying the given constraints.

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int n;
int k;
int total;
int possibilities;
int left;


cout << "Enter Number of Rows: ";
cin >> n;

cout << "Enter Number of columns: ";
cin >> k; //

if(n>0 || k>0)
{
    total=pow(2,(n*k));
    //Total number of possibilities with 0's and 1's
    left=((pow(k,2))-(pow((k/n),2)));
    //Calculating possible ways which need to be remove ,because no 0's in a single column
    possibilities=total-k*left-1;
    //Final calculation by removing empty matrix.
    cout << "Number of Matrices are with 0's and 1's: " <<total << endl;
    cout << "The matrices may not contain any column of all zero values"<< endl;
    cout <<"Number of possibilities without any 0' columns are"<<possibilities << endl;
}
else
{
      cout<<"The Values of n and k should be greater than zero";
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote