1. Write a C# Sharp program to find the sum of first 10 natural numbers. Go to the editor
Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
2. Write a program in C# Sharp to make such a pattern like a pyramid with numbers increased by 1.
1
2 3
4 5 6
7 8 9 10
// first
using System;
namespace ConsoleApplication1
{
internal class Program
{
public static void Main(string[] args)
{
var sum = 0;
for (var i = 1; i <= 10; i++)
{
sum += i;
}
Console.WriteLine($"The Sum is : {sum}");
}
}
}
// second
using System;
namespace ConsoleApplication1
{
internal class Program
{
public static void Main(string[] args)
{
var num = 1;
for (var i = 1; i <= 4; i++)
{
for (var j = 1; j <= i; j++)
{
Console.Write($"{num} ");
num += 1;
}
Console.Write("\n");
}
}
}
}
Comments
Leave a comment