Create function power() in c++.
CODING:
#include<iostream.h>
#include<conio.h>
void main()
{
double power(double,int);
int n;
double m,ans;
clrscr();
cout<<"Enter base Number:";
cin>>m;
cout<<"Enter Raise Number:";
cin>>n;
ans=power(m,n);
cout<<"POWER OF "<<m<<" INTO "<<n<<'='<<ans;
getch();
}
double power(double a,int b)
{
int i;
double ans=1;
for(i=1;i<=b;i++)
{
ans=ans*a;
}
return(ans);
}
6.Create function power() in c++ and default argument.
CODING:
#include<iostream.h>
#include<conio.h>
void main()
{
double power(double,int=2); /*function declaration*/
int n;
double m,ans;
clrscr();
cout<<"Enter base Number:";
cin>>m;
cout<<"Enter Raise Number:";
cin>>n;
ans=power(m); /*calling function*/
cout<<"POWER OF "<<m<<" INTO "<<n<<'='<<ans;
getch();
}
double power(double a,int b) /*defination function*/
{
int i;
double ans=1;
for(i=1;i<=b;i++)
{
ans=ans*a;
}
return(ans);
}
CODING:
#include<iostream.h>
#include<conio.h>
void main()
{
double power(double,int);
int n;
double m,ans;
clrscr();
cout<<"Enter base Number:";
cin>>m;
cout<<"Enter Raise Number:";
cin>>n;
ans=power(m,n);
cout<<"POWER OF "<<m<<" INTO "<<n<<'='<<ans;
getch();
}
double power(double a,int b)
{
int i;
double ans=1;
for(i=1;i<=b;i++)
{
ans=ans*a;
}
return(ans);
}
6.Create function power() in c++ and default argument.
CODING:
#include<iostream.h>
#include<conio.h>
void main()
{
double power(double,int=2); /*function declaration*/
int n;
double m,ans;
clrscr();
cout<<"Enter base Number:";
cin>>m;
cout<<"Enter Raise Number:";
cin>>n;
ans=power(m); /*calling function*/
cout<<"POWER OF "<<m<<" INTO "<<n<<'='<<ans;
getch();
}
double power(double a,int b) /*defination function*/
{
int i;
double ans=1;
for(i=1;i<=b;i++)
{
ans=ans*a;
}
return(ans);
}
Comments
Post a Comment