StoimenK

C# 1.9 Sum of Odd Numbers

Jan 20th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _1._9_Sum_of_Odd_Numbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int number = int.Parse(Console.ReadLine());
  14.  
  15.             int sum = 0;
  16.             int n = 0;
  17.  
  18.             for (int i = 1; i <= number; i++)
  19.             {
  20.                 n = 2 * i - 1;
  21.                 Console.WriteLine(n);
  22.                 sum += n;
  23.             }
  24.             Console.WriteLine($"Sum: {sum}");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment