netjunky

func5_1

Sep 26th, 2010
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int func5_1(int a, int b, int h);
  6.  
  7. // Y = log( sqrt( exp( X - 1 ) ) )
  8. int func5_1(int a, int b, int h) {
  9.  
  10.     double y = 0;
  11.     int x = 0;
  12.     int i = 0;
  13.    
  14.     if((b <= 0) || (h <= 0)) {
  15.         fprintf(stderr, "b or h should be higher then 0\n");
  16.         return 0;
  17.     }
  18.    
  19.     do {
  20.         if(i == 0) {
  21.             x = a;
  22.         } else if(i == 1) {
  23.             x = a + h;
  24.         } else {
  25.             x = a + h + i;
  26.         }
  27.        
  28.         y = log( sqrt( exp( (double)(x - 1) ) ) );
  29.        
  30.         printf("With y = %3.2lf as result and b = %d as limit\n", y, b);
  31.        
  32.         i++;
  33.     } while(y <= (double)b);
  34.    
  35.     return 0;
  36. }
  37.  
  38. int main(int argc, char **argv) {
  39.     func5_1(-1, 20, 20);
  40.    
  41.     return 0;
  42. }
Add Comment
Please, Sign In to add comment