Advertisement
martinvalchev

Sum_of_Odd_Numbers

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