[Solved] Calculate the algebraic expression in C# [closed]


  • p has to be initialized to 1 as 0 * X == 0
  • Also i and j (why not k) have to be initialized to 1 as it is required by your formula
  • You have to sum up the products after the products where calculated as you would add 1 to the correct result otherwise and you would not add the last calculated product

So the code below should give the correct result:

        float sum = 0;

        int n = Console.Read();

        for (int i = 1; i <= n; i++)
        {

          float p = 1;
          for (int k = 1; k <= i+2; k++)
          {
            p *= (3 * k + 2);
          }              

          sum += p;
        }

3

solved Calculate the algebraic expression in C# [closed]