Advertisement
ekostadinov

CalculateSum

Nov 12th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.CalculateSum
  8. {
  9.     class CalculateSum
  10.     {
  11.         static int N;
  12.         static int X;
  13.         static int index;        
  14.         static decimal factorialOfN;
  15.         static decimal resultPow;
  16.         static decimal sum;
  17.        
  18.        
  19.                
  20.        
  21.         static void Main()
  22.         {
  23.             Console.WriteLine("Enter value for N: ");
  24.             N = int.Parse(Console.ReadLine());
  25.  
  26.             Console.WriteLine("Enter value for X: ");
  27.             X = int.Parse(Console.ReadLine());
  28.  
  29.             while (N < 1)
  30.             {
  31.                 Console.WriteLine("Incorrect input!");
  32.                 Console.Write("enter value for N:");
  33.                 N = int.Parse(Console.ReadLine());
  34.             }
  35.  
  36.             DoSomeMath();
  37.         }
  38.  
  39.         private static void DoSomeMath()
  40.         {
  41.             for (index = 1; index <= N; index++)
  42.             {
  43.                 factorialOfN = 1;
  44.                 resultPow = 1;
  45.                 sum = 1;
  46.  
  47.                 for (int inner = 1, index2 = 1; inner <= index && index2 <= index; inner++, index2++)
  48.                 {
  49.                    factorialOfN *= inner;                    
  50.                    resultPow *= X;
  51.                            
  52.                       for (int index3 = 1; index3 <= N; index3++)
  53.                       {
  54.                           sum = (decimal)factorialOfN / (decimal)resultPow;                                                              
  55.                       }                            
  56.                      
  57.                 }
  58.                
  59.  
  60.             Console.WriteLine(index + "index");
  61.             Console.WriteLine(factorialOfN + "fac");
  62.             Console.WriteLine(resultPow + "pow");
  63.             Console.WriteLine(sum + "maybe");
  64.            
  65.             Console.WriteLine();
  66.             }
  67.             //Console.WriteLine("The sum of S = 1 + 1!/X + 2!/X^2 + … + N!/X^N is {0}", sum + 1);
  68.            
  69.         }
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement