Problem Statement:: Department of Computer Science and Engineering

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Program No :1 Date:
Program Title :FUNCTION POWER USING DEFAULT VALUES

Problem Statement: Write a function power to raise a number m to


power n. The function takes a double value for m and int value for n. Use
default value for n to make the function to calculate squares when this
argument is omitted.
Key Concept: 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

OBJECT ORIENTED PROGRAMMING THROUGH C++ LABORATORY 2018 BATCH 1


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

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:

OBJECT ORIENTED PROGRAMMING THROUGH C++ LABORATORY 2018 BATCH 2

You might also like