Object
Write a program to print the value of a number raised to power of another.
Algorithm
- Declare integer variables num, pow, i and value.
- Set value = 1.
- Read num and pow.
- Set i = 1.
- Repeat WHILE i <= pow
- value = value * num.
- Write “num *”.
- i++.
- [End of WHILE loop.]
- Write “= value”.
- Exit.
Flowchart

C++ Source Code
// program 51
#include<iostream>
using namespace std;
int main()
{
int num, pow, i, value = 1;
cout << "Enter any number: ";
cin >> num;
cout << "Enter the power: ";
cin >> pow;
i = 1;
while (i <= pow)
{
cout << num << " * ";
value = value * num;
i++;
}
cout << "\b\b= " << value;
return 0;
}
C Source Code
/*program 51*/
#include<stdio.h>
int main()
{
int num, pow, i, value=1;
printf("Enter any number: ");
scanf("%d", &num);
printf("Enter the power: ");
scanf("%d", &pow);
i = 1;
while(i<=pow)
{
printf("%d * ", num);
value = value * num;
i++;
}
printf("\b\b= %d", value);
return 0;
}
Output
Enter any number: 5
Enter the power: 4
5 * 5 * 5 * 5 = 625
