Calculate mn where n is an integer remember no pow a for Pri

Calculate m^n where n is an integer remember: no pow(), a for) Print 1/3+ 1/4+ 1/5+ 1/6+ 1/7

Solution


c) using while loop

//calculating power of a number using while loop
#include <iostream>
using namespace std;

int main()
{
    int m;
    float n,result = 1;

    cout << \"Enter base and exponent respectively: \";
    cin >> m>> n;

    cout << m<< \"^\" << n<< \" = \";
//calculaing the power and storing in result,the number of times loop gets executed is equal to the power
    while (n!= 0)
{
        result *= m;
        --n;
    }

    cout << result;
   return 0;
}


using for loop

//calculating power of a number using for loop
#include <iostream>
using namespace std;

int main()
{
    int m;
    float n,result = 1;

    cout << \"Enter base and exponent respectively: \";
    cin >> m>> n;

    cout << m<< \"^\" << n<< \" = \";
//calculaing the power and storing in result,the number of times loop gets executed is equal to the power
for(int i=0;i<n;i++)
{
result*=m;

}
    cout << result;

    return 0;
}


d)
//program to print 1/3+1/4+1/5+1/6+1/7
#include <iostream>
using namespace std;

int main()
{
//taking j as numerator and i as denominator and assigning j as 1 as numerator is 1 in the given expression
int i,j=1;
//loop starts from 3 to 7 as we want values from 3 to 7 to be displayed as denominator
for(int i=3;i<=7;i++)
{
cout<<j<<\"/\"<<i;
//checking if the value is less than 7 as we don\'t want \"+\" to be displayed after 7 that is at the end
if(i<7)
cout<<\"+\";
}
return 0;
}

 Calculate m^n where n is an integer remember: no pow(), a for) Print 1/3+ 1/4+ 1/5+ 1/6+ 1/7Solution c) using while loop //calculating power of a number using
 Calculate m^n where n is an integer remember: no pow(), a for) Print 1/3+ 1/4+ 1/5+ 1/6+ 1/7Solution c) using while loop //calculating power of a number using

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site