0% found this document useful (0 votes)
4 views2 pages

Lab07

The document describes a C++ program that defines two overloaded functions named 'pow' to calculate the power of a number, one for double and one for int types. The main function prompts the user to input a number and a power, then calls both versions of the 'pow' function to display the results. There are some variable naming inconsistencies in the code that need correction for proper functionality.

Uploaded by

yp23128
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Lab07

The document describes a C++ program that defines two overloaded functions named 'pow' to calculate the power of a number, one for double and one for int types. The main function prompts the user to input a number and a power, then calls both versions of the 'pow' function to display the results. There are some variable naming inconsistencies in the code that need correction for proper functionality.

Uploaded by

yp23128
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program-07

/*Write a function that performs the same operation as that of the last program but
takes an int value for m. Both the functions should have the same name. Write a main
that calls both the functions.
*/

#include <iostream>
using namespace std;
double pow(double m,int n=2)
{
double res=1;
for(int i=1;i<=n;i++)
res*=m;
return res;
}
double pow(int m,int n=2)
{
double res=1;
for(int i=1;i<=n;i++)
res*=m;
return res;
}

int main()
{
double n;
int n2,n;
cout<<"Enter Number : ";
cin>>n1;
cout<<"Enter Power : ";
cin>>n;
cout<<num1<<" raised to the power "<<n<<"= "<<pow(n1,n)<<endl;
cout<<"Enter Number : ";
cin>>n2;
cout<<"Enter Power : ";
cin>>n;
cout<<num2<<" raised to the power "<<n<<"= "<<pow(n2,n);
}
Output

You might also like