Advertisement
VelizarAvramov

09. Sum of Odd Numbers

Dec 16th, 2019
121
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 _09._Sum_of_Odd_Numbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int number = int.Parse(Console.ReadLine());
  10.  
  11.             int sum = 0;
  12.  
  13.             for (int i = 1; i <= number * 2; i+=2)
  14.             {
  15.                 Console.WriteLine(i);
  16.                 sum += i;
  17.             }
  18.             Console.WriteLine($"Sum: {sum}");
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement