dxnge

Untitled

Oct 9th, 2022
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp7
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double x = Convert.ToDouble(Console.ReadLine());
  10.  
  11.             while (Math.Abs(x) > 1)
  12.             {
  13.                 Console.Write($"x value isn’t in the interval.Input value on interval(-1; 1): ");
  14.                 x = Convert.ToDouble(Console.ReadLine());
  15.             }
  16.  
  17.             double s = 1;
  18.             double cur_num = x;
  19.             for (int i = 2; cur_num >= 0.0001; i += 2)
  20.             {
  21.                 double loc_num = x;
  22.                 for (int n = 1; n < i; n++)
  23.                 {
  24.                     loc_num *= x;
  25.                 }
  26.                 s += loc_num;
  27.                 cur_num = loc_num;
  28.             }
  29.             Console.WriteLine($"s == {s}");
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment