Sunday, June 2, 2024

Addition of Four Numbers in C#

Program Listing

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            // Variables to store the four numbers

            double num1, num2, num3, num4;


            Console.Write("\n\n\tAddition of Four Numbers in C#\n\n");

            


            // Prompt the user for the first number

            Console.Write("\tEnter the first number: ");

            num1 = Convert.ToDouble(Console.ReadLine());


            // Prompt the user for the second number

            Console.Write("\tEnter the second number: ");

            num2 = Convert.ToDouble(Console.ReadLine());


            // Prompt the user for the third number

            Console.Write("\tEnter the third number: ");

            num3 = Convert.ToDouble(Console.ReadLine());


            // Prompt the user for the fourth number

            Console.Write("\tEnter the fourth number: ");

            num4 = Convert.ToDouble(Console.ReadLine());


            // Calculate the sum of the four numbers

            double sum = num1 + num2 + num3 + num4;


            // Display the result

            Console.WriteLine("\n\tThe sum of the four numbers is: " + sum+ ".");

            Console.ReadKey();

        }

    }

}

 

No comments:

Post a Comment