Write a C# Sharp program to display the n terms of odd natural numbers and their sums.
using System; public class OddNaturalNumbers { public static void Main(string[] args) { int n, sum = 0; Console.Write("Enter the number of terms: "); n = Convert.ToInt32(Console.ReadLine()); Console.Write("The first " + n + " odd natural numbers are: "); for (int i = 1; i <= n; i++) { Console.Write(2 * i - 1 + " "); sum += 2 * i - 1; } Console.WriteLine(); Console.WriteLine("The sum of the first " + n + " odd natural numbers is: " + sum); } }
Write a C# Sharp program to display the n terms of odd natural numbers and their sums.
Reviewed by Bhaumik Patel
on
12:06 AM
Rating: