Index « Previous Next »

Question

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

Source Code

#include <stdio.h>

int main()
{
    int i, base, power, result = 1;
    
    printf("Enter a number :");
    scanf("%d", &base);
    printf("Enter the power it raised to :");
    scanf("%d", &power);

    for (i = 1; i <= power; i++)
    {
        result *= base;
    }

    printf("The result is %d", result);
    
    return 0;
}

Output

Enter a number :6
Enter the power it raised to :4
The result is 1296