Facebook
From Kamil, 6 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 270
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4.  
  5. void main(){
  6.         double blad=1;
  7.         int el=0;
  8.         double x;
  9.         int i, j, k;
  10.         double szereg;
  11.         double eps;
  12.         do{
  13.                 printf("Podaj wartosc x");
  14.                 scanf_s("%lf", &x);
  15.         } while (x<=0.00 || x>2.00);
  16.         printf("Podaj wartosc eps");
  17.         scanf_s("%lf", &eps);
  18.         double a=1;
  19.         double b=1;
  20.         szereg = 0;
  21.        
  22.  
  23.         for (i = 1;blad>eps ; i++)
  24.         {
  25.                 for (j = 0; j <= i ; j++)
  26.                 {
  27.                         a *= (-1);
  28.        
  29.                 }
  30.  
  31.                 for (k = 1; k < i; k++)
  32.                 {
  33.                         b *= (x - 1);
  34.                
  35.                 }
  36.  
  37.                 szereg += (a / i)*b;
  38.  
  39.                 blad = fabs(log(x)-szereg);
  40.         }
  41.         printf("\nWartosc dokladna wynosi %lf", log(x));
  42.         printf("\nWartosc przyblizona wynosi %lf", szereg);
  43.         printf("\nWzieto %d elementow szeregu do oblczienia sumy", i);
  44.  
  45. }