April 19, 2020

How to write a program in C# to print first 10 even number.

Write a program to print the product of the first 10 even numbers.

How to write a program in C# to print first 10 even number.

Sample Solution

C# Sharp Code

using System;
using System.Collections.Generic;
using System.Text;
namespace Divisible
{
    class Even_Number
    {
        static void Main(string[] args)
        {
            int nNum, nEven;
            double nProd;
            nNum = 2; nEven = 0; nProd = 1;
            while (nEven < 10)
            {
                nProd = nNum * nProd;
                nNum = nNum + 2;
                nEven = nEven + 1;
 Console.WriteLine("The first 10 even numbers is:{0}", nProd);
            }
            Console.ReadLine();
        }
    }
}


                                                             Sample Output


How to write a program in C# to print first 10 even number.



No comments:

Post a Comment