mercredi 10 mars 2021

Q - Given positive integers- m,n.. Find and print the values of 3^min(m,n) and 2^max(m,n)

Using C++ have written foloowing :

#include <iostream>
using namespace std;
int main()
{
    int m,n;
    int threemin, twomax;
    threemin = 1; twomax = 1;
    cout<<"Enter m"<<"Enter n";
    cin>>m>>n;
    int i,j;
    for ((i = 1, j = 1) ; ( (i <= m), (j <= n) ) ; (i++,j++))
    {
        if (m>n){ i <= n ; threemin = threemin*3;}  //  for changing max value of i if m > n because we want to print 3^min(m,n)
        else {  threemin = threemin*3 ;} ; // 
        if (m>n){ j <= m ; twomax = twomax*2;} // same for changing j
        else {  twomax = twomax*2 ; } 
        
        
    }
    cout<<"Threemax is"<<threemin<<"Twomax is"<<twomax;
    return 0;
    
}

Issue -

  1. if m>n twomax gives valuto j<m and but my intentions are j<= m.
  2. code donot work well for m < n.

I am beginner .Kindly help me rectifying .

Aucun commentaire:

Enregistrer un commentaire