C Program

Object:-Write a Program to Calculate the Power of a Number

#include <stdio.h>
int main()
    int base, exponent;
    long long result = 1;
    printf("Enter a base number: ");
    scanf("%d", &base);
    printf("Enter an exponent: ");
    scanf("%d", &exponent);
    while (exponent != 0)
        result *= base;
    printf("Answer = %lld", result);
    return 0;


Enter a base number: 2
Enter an exponent: 4
Answer = 16


  • The program takes two integers from the user (a base number and an exponent) and calculates the power.

You may also like: