Q:

C++ program to find the power of a number using loop

belongs to collection: C++ programs on various topics

0

C++ program to find the power of a number using loop

All Answers

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

C++ code to find power of a number using loop

#include <iostream>
using namespace std;

int main()
{
    int num;
    int a = 1;
    int pw;

    cout << "Enter a number: ";
    cin >> num;
    cout << "\n";

    cout << "Enter a power : ";
    cin >> pw;
    cout << "\n";

    for (int i = 1; i <= pw; i++) {
        a = a * num;
    }

    cout << a;

    return 0;
}

Output

 
Enter a number: 5

Enter a power : 4

625

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

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to extract and print digits in reverse... >>
<< C++ program to determine the color of chess square...