petarkobakov

Sum of odd nums

May 23rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 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 sum = 0;
  11. int oddNum = 1;
  12.  
  13. for (int i = 0; i < n; i++)
  14. {
  15. sum += oddNum;
  16. Console.WriteLine(oddNum);
  17. oddNum += 2;
  18. }
  19. Console.WriteLine($"Sum: {sum}");
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment