Power Function

Lab C Beginner 10 points

Write int power(int base, int exp) using a loop (no math.h). Print base^exp for each input pair.

Input

n, then n lines base exp.

Output

n lines.

Example

Input

3
2 10
5 0
-3 3

Output

1024
1
-27
Sample input available Sample output available
Editor
C

Hints

Multiply result by base, exp times.

Solution explanation

Anything to the power 0 is 1, which the loop handles by never running.

Show solution
#include <stdio.h>

int power(int base, int exp) {
    int result = 1;
    for (int i = 0; i < exp; i++) result *= base;
    return result;
}

int main() {
    int n, b, e;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &b, &e);
        printf("%d\n", power(b, e));
    }
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD