Advertisement
bacco

Sum of Odd Numbers

May 18th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _08_Sum_of_Odd_Numbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var n = int.Parse(Console.ReadLine());
  10.             var sum = 0;
  11.  
  12.             for (int i = 1; i <= n * 2; i += 2)
  13.             {
  14.                 Console.WriteLine(i);
  15.                 sum += i;
  16.             }
  17.             Console.WriteLine($"Sum: {sum}");
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement