Advertisement
Qrist

Sum of Odd Numbers (Easy way)

Apr 12th, 2020
204
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.     static void Main(string[] args)
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int sum = 0;
  9.         for (int i = 1; i <=n; i++)
  10.         {
  11.             Console.WriteLine("{0} ", 2 * i - 1);
  12.             sum += 2 * i - 1;
  13.         }
  14.         Console.WriteLine("Sum: "+ sum);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement