Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a program that prints the next n odd numbers (starting from 1) and on the last row prints the sum of them.
- using System;
- namespace _08._Sum_of_Odd_Numbers
- {
- class SumOfOddNumbers
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int sum = 0;
- for (int i = 1; i <= n; i++)
- {
- Console.WriteLine("{0}", 2 * i - 1);
- sum += 2 * i - 1;
- }
- Console.WriteLine($"Sum: {sum}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment