C++ Exercises: Find power of any number using for loop
C++ For Loop: Exercise-62 with Solution
Write a program in C++ to find the power of any number using a for loop.
Pictorial Presentation:

Sample Solution:-
C++ Code :
#include <iostream>
using namespace std;
int main()
{
int bs, ex, num=1,i;
cout << "\n\n Find power of any number using for loop:\n";
cout << "---------------------------------------------\n";
cout << " Input the base: ";
cin >> bs;
cout << " Input the exponent: ";
cin>>ex;
for (i = 1; i <=ex; i++)
{
num=num*bs;
}
cout <<bs<<" ^ "<<ex<<" = "<<num<<endl ;
}
Sample Output:
Find power of any number using for loop: --------------------------------------------- Input the base: 2 Input the exponent: 5 2 ^ 5 = 32
Flowchart:

C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to print all ASCII character with their values.
Next: Write a program in C++ to enter any number and print all factors of the number.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join