Advertisement
Kalhnyxtakias

lab7extra

Dec 13th, 2020
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define N 10
  4.  
  5. double exponential(double x, int y){
  6.     double number = 1;
  7.     int i;
  8.    
  9.     for(i = 1; i<=y; i++){
  10.         number *= x;
  11.     }
  12.     return number;
  13. }
  14.  
  15. double expression(double x, int n){
  16.     double num,den;
  17.     num = exponential((x-1)/(x+1), (2*n)-1);
  18.     den = (2*n) - 1;
  19.     return (num/den);
  20. }
  21.  
  22. double sum(double x, int n){
  23.     int i;
  24.     double suma = 0;
  25.  
  26.     for(i=1; i<=n; i++){
  27.         suma += expression(x,i);
  28.     }
  29.     return 2*suma;
  30. }
  31.  
  32. int main(int argc, char* argv[]){
  33.     double x;
  34.    
  35.     do{
  36.         printf("Enter x: ");
  37.         scanf("%lf", &x);
  38.         if(x<=0 || x > 6){
  39.             printf("Invalid value!\n");
  40.         }
  41.     }while(x<= 0 || x > 6);
  42.  
  43.     printf("\nseries ln(%.3lf): %.15lf", x, sum(x,N));
  44.     printf("\nmath ln(%.3lf): %.15lf\n", x, log(x));
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement