0% found this document useful (0 votes)
8 views1 page

5cpp Program

This C program demonstrates various mathematical functions from the math.h library, including square root, power, ceiling, floor, sine, absolute value, natural logarithm, and exponential functions. It uses sample values to showcase the output of each function. The program includes necessary headers and performs calculations with both degrees and radians.

Uploaded by

Netra Yardoni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

5cpp Program

This C program demonstrates various mathematical functions from the math.h library, including square root, power, ceiling, floor, sine, absolute value, natural logarithm, and exponential functions. It uses sample values to showcase the output of each function. The program includes necessary headers and performs calculations with both degrees and radians.

Uploaded by

Netra Yardoni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

3. Program to demonstrate library functions in math.

#include <stdio.h> // For input/output functions like printf


#include <math.h> // For mathematical functions

int main() {
double num = 9.0;
double base = 2.0;
double exponent = 3.0;
double angle_degrees = 45.0;
double val_ceil_floor = 3.7;

// Square Root function: sqrt()


printf("Square root of %.2lf: %.2lf\n", num, sqrt(num));

// Power function: pow()


printf("%.2lf raised to the power of %.2lf: %.2lf\n", base, exponent, pow(base, exponent));

// Ceiling function: ceil() - rounds up


printf("Ceiling of %.1lf: %.1lf\n", val_ceil_floor, ceil(val_ceil_floor));

// Floor function: floor() - rounds down


printf("Floor of %.1lf: %.1lf\n", val_ceil_floor, floor(val_ceil_floor));

// Sine function: sin() - takes radians, convert degrees to radians using M_PI
double angle_radians = angle_degrees * (M_PI / 180.0); // M_PI is a macro in math.h
printf("Sine of %.0lf degrees: %.2lf\n", angle_degrees, sin(angle_radians));

// Absolute value function: fabs() for double


double negative_val = -10.5;
printf("Absolute value of %.1lf: %.1lf\n", negative_val, fabs(negative_val));

// Logarithm (natural log): log()


printf("Natural logarithm of %.2lf: %.2lf\n", num, log(num));

// Exponential function: exp() - e raised to the power of x


printf("e raised to the power of %.2lf: %.2lf\n", base, exp(base));

return 0;
}

You might also like