Facebook
From Kamil, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 278
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. void main(){
  5.         double x;
  6.         double logarytm;
  7.         int i, j,k;
  8.         int n;
  9.         double szereg;
  10.         double eps;
  11.         printf("Podaj wartosc x");
  12.         scanf_s("%d", &x);
  13.         printf("Podaj ilsoc elementow szeregu do obliczenia sumy");
  14.         scanf_s("%d", &n);
  15.         double a = 0;
  16.         double b = 0;
  17.         logarytm = ln(x);
  18.         szereg = 0;
  19.         eps = 0;
  20.         for (i = 1; szereg > eps; i++)
  21.         {
  22.                 for (j = i+1; j <= i+1; j++)
  23.                 {
  24.                         a *= -1;
  25.                 }
  26.                
  27.                 for (k = i; k <= i;k++)
  28.                         b *= (x - 1);
  29.  
  30.                 szereg += (a / i)*b*(x - 1) - (1 / 2)*(x - 1)*(x - 1);
  31.  
  32.                 eps = abs(logarytm - szereg);
  33.         }
  34.  
  35.         printf("Wartosc dokladna wynosi %lf", logarytm);
  36.         printf("Wartosc przyblizona wynosi %lf", szereg);
  37.         printf("Wzieto %d elementow szeregu do oblczienia sumy", i);
  38.  
  39. }