Q:

C++ Program to Find Power of a Number using for loop

belongs to collection: C++ Basic Solved Programs

0

Write a C++ Program to Find Power of a Number using for loop. Here’s simple Program to Calculate Power of Number using for loop in C++ Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The program below takes two integers from the user (a base number and Power to base) and calculates the power.

 
 

For example :: In case of 25

  • 2 is the base number
  • 5 is the power to the base number
  • And, the power of number is equal to 2*2*2*2*2

Here is source code of the C++ Program to Find Power of a Number using for loop. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : 

/*  C++ Program to Find Power of a Number using for loop  */

#include<iostream>
using namespace std;

int main()
{
   int b,p,i,pow=1;
   cout<<"Enter base of a number :: ";
   cin>>b;
   cout<<"\nEnter power to a base [ "<<b<<" ] :: ";
   cin>>p;

   for(i=p;i>0;i--)
   {
        pow=pow*b;
   }
   cout<<"\nPower of a Number [ "<<b<<" ^ "<<p<<" ] :: "<<pow<<"\n";

  return 0;
  }

Output : :


/*  C++ Program to Find Power of a Number using for loop  */

Enter base of a number :: 2

Enter power to a base [ 2 ] :: 6

Power of a Number [ 2 ^ 6 ] :: 64

Process returned 0

Above is the source code for C++ Program to Find Power of a Number using for loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Basic Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Program to Find Sum and Average of n numbers u... >>
<< C++ Program to find Sum of Digits of a Number usin...