Assignments » Flow Of Control » Set2 » Solution 4

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.

 

#include<iostream.h>
#include<conio.h>

int main()
{
	int n,p,r=1;
	cout<<"Enter the base number and exponent ";
	cin>>n>>p;

	for(int i=1;i<=p;i++)
		r=r*n;

	cout<<"Result :"<<r;

	getch();
	return 0;
}

 

 

 

#include<iostream>
using namespace std;

int main()
{
	int n,p,r=1;
	cout<<"Enter the base number and exponent ";
	cin>>n>>p;

	for(int i=1;i<=p;i++)
		r=r*n;

	cout<<"Result :"<<r;

	cin.ignore();
	cin.get();
	return 0;
}

 

 

Enter the base number and exponent : 5 3
Result :125

 

«back