Advertisement
Guest User

Untitled

a guest
Oct 14th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. #define CUBE(X) (X)*(X)*(X)
  6. #define SQUARE(X) (X)*(X)
  7.  
  8. const char * __out_format = "%0.3f \t %0.3f \n";
  9.  
  10. float calc_func_value( float x )
  11. {
  12.       if( x > 2 ) {
  13.             return tanf( (CUBE(x) - 1) * 0.5 ) + sqrtf(x);
  14.       }
  15.       if ( x > 0 && x <= 2 ) {
  16.             return logf(2.0/3.0 * x) - sinf(0.5 * x );
  17.       }
  18.       return expf(-1*x) + 2 * SQUARE(x);
  19. }
  20.  
  21. void print_table(){
  22.       float start = -3.0F;
  23.       float step = 0.3F;
  24.       float end = 4.0F;
  25.       printf("x \t z \n");
  26.       for(float x = start ; x < end; x += step ){
  27.             float z = calc_func_value(x);
  28.             printf(__out_format, x, z);
  29.       }
  30. }
  31.  
  32.  
  33. int main( int __argc, char ** __argv ) {
  34.     print_table();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement