fork download
  1. namespace Problem_8.Sum_of_Odd_Numbers
  2. {
  3. using System;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. var loopLength = int.Parse(Console.ReadLine());
  10.  
  11. var sum = 0;
  12. var loopLengthCounter = 0;
  13. var oddNumbers = 1;
  14.  
  15. while (loopLengthCounter != loopLength)
  16. {
  17. Console.WriteLine(oddNumbers);
  18.  
  19. sum += oddNumbers;
  20. oddNumbers += 2;
  21. loopLengthCounter++;
  22. }
  23.  
  24. Console.WriteLine($"Sum: {sum}");
  25. }
  26. }
  27. }
Runtime error #stdin #stdout #stderr 0.01s 134976KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: String
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00006] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Int32.Parse (System.String s) [0x00007] in <8f2c484307284b51944a1a13a14c0266>:0 
  at Problem_8.Sum_of_Odd_Numbers.Program.Main () [0x00005] in <41ee312dc88e4c8abe69a4bb516c8376>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Value cannot be null.
Parameter name: String
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00006] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Int32.Parse (System.String s) [0x00007] in <8f2c484307284b51944a1a13a14c0266>:0 
  at Problem_8.Sum_of_Odd_Numbers.Program.Main () [0x00005] in <41ee312dc88e4c8abe69a4bb516c8376>:0