1.

C++ में प्रोटेक्टेड मेम्बर फंक्शन द्वारा m की घात n के मान ज्ञात कीजिए।

Answer»

#include<iostream.h>
#inclde<conio.h>
class Pow
{
int P, r;
public:
Pow()
{
p=1;
}

protected:

int comp_pow (int a, int b)
{
int i;
for (i=1; i<=b; i++)
p=p*a;
return p;
}
public:
void Result (int m, int n)
{
r=comp_pow (m, n) ;
cout<<"m to the power of n = "<<r;
}
};
void main()
{
clrscr();
Pow obj:
int m, n;
cout<<"Enter the values of m and n:"; cin>>m>>n;
obj. Result (m, n) ;
getch();
}

आउटपुट

Enter the values of m and n: 5
3
m to the power of n = 125



Discussion

No Comment Found