Professional Documents
Culture Documents
Problem Statement:: Department of Computer Science and Engineering
Problem Statement:: Department of Computer Science and Engineering
Problem Statement:: Department of Computer Science and Engineering
Program No :1 Date:
Program Title :FUNCTION POWER USING DEFAULT VALUES
Program:
#include<iostream.h>
#include<conio.h>
void power(int n,int m=2);
void main()
{
int n,x,m;
clrscr();
cout<<"Enter the value of n";
cin>>n;
cout<<"if m exists x=1";
cout<<"if m exists x=0";
cin>>x;
if(x==1)
{
cout<<"Enter m";
cin>>m;
power(n,m);
}
else
power(n);
getch();
}
void power(int n,int m)
{
int p=1;
for(int i=1;i<=m;i++)
p=p*n;
cout<<n<<"^"<<m<<"="<<p;
}
Input/Output: