C Programming Examples Tutorial Index

C Loop Programs

Here is a C program that calculates an employee's bonus and gross salary based on their basic salary. The purpose of this program is to demonstrate basic mathematical calculations using C.

Example Program:

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

void main()
    double base, exponent, result;

    printf("Enter the base: ");
    scanf("%lf", &base);

    printf("Enter the exponent: ");
    scanf("%lf", &exponent);

    result = pow(base, exponent);

    printf("%.2lf to the power of %.2lf is %.2lf\n", base, exponent, result);

Program Output:

Enter the base: 10
Enter the exponent: 4
10.00 to the power of 4.00 is 10000.00

This program begins by including the header files stdio.h and math.h. The stdio.h header file provides functions for input and output, and the math.h header file provides mathematical functions, such as pow().

In the main() function, the program declares three variables: base, exponent, and result. The program then prompts the user to enter the base and exponent using the printf() function, and reads the input using the scanf() function.

Next, the program calculates the power of the base to the exponent using the pow() function from the math.h library, and stores the result in the result variable. Finally, the program prints the result using the printf() function.

This is just a simple example, but it illustrates how to use the pow() function from the math.h library to calculate the power of a number in a C program.

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram