help

Updated on October 15, 2018 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on October 15, 2018

I am training in C# and we are in the Flow control looping and I am quite rusty in Math.  I was given 2 problems and I am having doubts on the solutions. 

 

∑ 5 = 1+ 2 + 3 + 4 + 5

 

Is this correct?

 

 

{            int input;

 

           int som = 0;

 

           Console.Write(“Enter a natural number: “);

 

           input = Int32.Parse(Console.ReadLine());

 

           for (int i = 1; i <= input ; i++)

 

           {

 

               som += i;

 

           }

 

           Console.WriteLine(“The sum is ” + som);

 

           Console.ReadKey();

 

}

 

 

 

  • Liked by
Reply
0 on October 15, 2018

∑ 5 = 1+ 2 + 3 + 4 + 5 is not correct. That’s how it has to look like: Sum

But your code seems fine.

 

  • Liked by
Reply
Cancel
0 on October 15, 2018

hi!  thank you for your help!  But the code gives 120, the site gives 55

 

  • Liked by
Reply
Cancel
0 on October 15, 2018

By the way this is correct ∑ 5 = 1+ 2 + 3 + 4 + 5

the code poses problem. 

 

  • Liked by
Reply
Cancel
0 on October 15, 2018

The code is OK

  • Liked by
Reply
Cancel