Advertisement
Spocoman

09. Sum of Odd Numbers

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