programminginc.net

C Language Programming

  • Home
  • C Examples
Home > C Programming > Math functions in c programming examples

Math functions in c programming examples

/* 
   C program demonstrates the use of some functions in the math library.
*/

#include<stdio.h>

// The following preprocessor directive is necessary 
// if you want to use the math library functions.
#include<math.h>

// The following preprocessor directive defines
// the constant PI
#define PI 3.1415927

main() {
   double x, y ;
   double z ;

   printf("x = ") ;       // prompt for x
   scanf("%lf", &x) ;

   printf("y = "  ) ;     // prompt for y
   scanf("%lf", &y) ;

   // Compute some values using x & y

   z = sqrt(x) ;
   printf("The square root of %f is %f\n", x, z) ;

   printf("x^y = %f\n", pow(x,y)) ;

   printf("sin(PI * %f) = %f\n", y, sin(PI*y) ) ;
}

post ajax

No post

Copyright © 2021  programminginc.net