Bob103

C#_Methods_1

Sep 16th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. class Program
  2.     {
  3.         public static int Factorial(int numb)
  4.         {
  5.             int res = 1;
  6.             for (int i = numb; i > 1; i--)
  7.                 res *= i;
  8.             return res;
  9.         }
  10.  
  11.         static void Main(string[] args)
  12.         {
  13.             double e = 0.0001;
  14.             //Console.Write(e);
  15.             int m = int.Parse(Console.ReadLine());
  16.             double sum = 1;
  17.             int j = 2;
  18.             int j1 = 4;
  19.  
  20.             for (int i = 1; i < m; i++)
  21.             {
  22.                 sum +=((Math.Cos(Math.Pow(i,2)))) / Factorial(j) -
  23.                     (Math.Cos(Math.Pow(i,2))) / Factorial(j1);
  24.                 j += 4;
  25.                 j1 += 4;
  26.                 Console.WriteLine(sum);
  27.  
  28.                 if(Math.Abs(sum) < e)
  29.                 {
  30.                     Console.Write("exit");
  31.                 }
  32.             }
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment