kirililchev3

Sum of Odd Numbers - for

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