C++ Programming Blog

 
 
 
/*Write a function power() to raise a number m to a power n.  The
function takes a double value for m and int value for n and returns
the result correctly.  Use a default value of 2 for n to make the
function to calculate squares when this argument is omitted.
Write a main that gets the values of m and n from the user to test
the function.*/

#include <iostream.h>
#include <conio.h>
void main()
{
double power(double m,int n=2);
clrscr();
cout<<endl<<endl<<endl;
int choice,m,n;
double result;
do
{
cout<<\"\\n\\n\\nCHOICES\\n\\n\";
cout<<\"1)    Only Value of M\\n\";
cout<<\"2)    Value for both M and N\\n\";
cout<<\"3)    QUIT\\n\";
cout<<\"ENTER YOUR CHOICE:-\";
cin>>choice;
clrscr();
cout<<endl<<endl<<endl;
switch(choice)
{
    case 1 : cout<<\"Enter Value for M:-\";
               cin>>m;
            result=power(m);
            cout<<\"Power function when default argument is used =\"<<result;
            break;
   case 2 : cout<<\"Enter Value for M and N:-\";
               cin>>m>>n;
            result=power(m,n);
            cout<<\"Power function when actual argument is use =\"<<result;
            break;
   case 3 : goto out;
   default: cout<<\"Entered Value is Invalid, Try again\";
}
}while(choice!=3);
out:
}


double power(double m,int n)
{
double pow=1,k=0;
for(int i=0;i<n;i++)
{
pow=pow*m;
}
return(pow);
}

    Related Post:
  1. Program to illusrate data conversion user defined data types using functions

  2. Program to show the implementation of Window-to-Viewport Coordinate Transformaton

  3. Program to implement Add and Subtract function on Big Number Class

  4. Program that differentiate b/w the variables of the storage class Auto and Static along with global variables

  5. Program to count number of words, lines and characters in given string

  6. Program to computes the n_th term of the fibonacci series using Dynamic Programming Technique

  7. Write a program to Add Two Matrix

  8. Program to draw different kinds of Thick Lines

  9. Program to implement the Kurskals Algorithm to solve Minimum Cost Spanning Tree Problem (MST) using Graphics with Mouse Support

  10. Program to display string triangle

  11. Program that computes the n_th term of the fibonacci series and also print the series upto the n_th term using recursion

  12. Program to implement the Binary search Algorithm

  13. Program of LL1 parser

  14. Program to draw an Ellipsoid using Parametric Equations

  15. Program to estimate the value of Second Derivative of the function at the given points from the given data using Central Difference Formula of order 2

  16. Program to show a 3D object using Polygon-Mesh Representation

  17. CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS

  18. Program to reverse the sequence of the words in the sentence and display the result

  19. Program of Nicol Lee Nicol Algorithm for Line Clipping

  20. Program for Fahrenheit to Celcius using Class

 
 
Didn't find what you were looking for? Find more on Write a function power() to raise a number m to a power n