Answer to Question #243457 in C# for Gayatri

Question #243457

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


1
Expert's answer
2021-10-01T07:45:58-0400
// 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");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS