Write a c program to input two numbers: a and b. next, compute the value of raised to the power of b.

1 minute read
3



Certainly! Here's a simple C program that takes two numbers 'a' and 'b' as input and computes the value of 'a' raised to the power of 'b':

    #include <stdio.h>
    #include <math.h>

    int main() {
        double a, b, result;

        // Input the values of 'a' and 'b'
        printf("Enter the value of 'a': ");
        scanf("%lf", &a);
   
        printf("Enter the value of 'b': ");
        scanf("%lf", &b);

        // Calculate the result
        result = pow(a, b);

        // Display the result
        printf("%.2lf raised to the power %.2lf is %.2lf\n", a, b, result);

        return 0;
    }

The output of this is:

    Enter the value of 'a': 2     Enter the value of 'b': 2     2.00 raised to the power 2.00 is 4.00

In this program, we use the pow() function from the math.h library to calculate the power of 'a' raised to 'b'. Make sure to compile and run this program in a C environment to use it.


Explore our website for valuable C programming resources and enhance your coding skills today!.


Learn C programming language from basic to advanced here (Click here or on the image)


Stay Strong, keep learning, and keep growing.