Facebook
From Bahadır Sina Terzioğlu, 1 Month ago, written in C#.
Embed
Download Paste or View Raw
Hits: 139
  1. using System;
  2.  
  3. class Technical_Test
  4. {
  5.     static void Main()
  6.     {
  7.         int[] array = { 1, 2, 2, 3, 3, 3, 5, 7, 11, 15 };
  8.         int n = array.Length;
  9.         double sum = 0;
  10.         for (int i = 0; i <= n - 1; i++)
  11.         {
  12.             double result = Result(array[i], i);
  13.             sum += result;
  14.             Console.WriteLine($"i = {i} -> {result}");
  15.         }
  16.         Console.WriteLine($"Sum: {sum}");
  17.     }
  18.  
  19.     static double Result(int x, int i)
  20.     {
  21.         double factorial = 1;
  22.         for (int j = 2; j <= i; j++)
  23.         {
  24.             factorial *= j;
  25.         }
  26.         return Math.Pow(x, i) / factorial;
  27.     }
  28. }