multiply

How to multiply two floating point numbers in C#

How to multiply two floating point numbers in C#

In this tutorial, we will discuss the concept of How to multiply two floating point numbers in C#

In this topic, we are going to learn how  to write a program for multipling two floating-point numbers in C# programming language

Multiplication of two floating-point numbers in C#

multiply two floating point numbers

Multiplication of two numbers using variable

In this program, the user declare and initialize two float variables num1 and num2. Then these two numbers are multiplied using multiplication(*) operator and then assigned the result to third (mul) variable

Program 1

// Calculate multiplication of two floating point numbers in C# program 
using System; 
public class Multiply_Float_Num { //Class declaration
    public static void Main(string[] args) { //declare main method inside the class
        float num1=10.5f; //declare and initailize float variable for num1
        float num2=20.6f;  //declare and initailize float variable for num2
        float mul=num1*num2; //Calculate multiplication of two floating-point numbers
        Console.WriteLine ("The multiplication of two given numbers: "+mul); } }
        //display output on the screen

When the above code is executed, it produces the following result

The multiplication of two given numbers: 216.3

 

Multiplication of two numbers – Entered by user

Program 2

In this program, the user is asked to enter two floating-point values. These two numbers are stored in variables n1 and n2 respectively and two numbers are multiplied using * operator
Then the product of n1 and n2 is evaluated and the result is stored in the mul variable. finally the result is displayed on the screen

// Calculate multiplication of two floating-point numbers in C# program 
using System; public class Mul_Of_Two_Floats { 
    public static void Main(string[] args) { 
        float num1, num2, mul; //declare float variables n1,n2 mul
        Console.WriteLine("calculate multiplication of two floating point numbers: "); 
        Console.Write("Input number to num1: "); 
        //Ask input from the user for num1
        num1=Convert.ToSingle(Console.ReadLine());
        //Reading the value for n1
        Console.Write("Input number to num2: ");
          //Ask input from the user for n2
        num2=Convert.ToSingle(Console.ReadLine());
            //Reading the value for n2
        mul=num1*num2; //calculate multiplication
        Console.WriteLine ("The multiplication of given two floating-point numbers: "+mul); //display result on the screen
        Console.ReadKey(); } }

When the above code is executed, it produces the following result

calculate multiplication of two floating point numbers:
Input number to num1: 15.5
Input number to num2: 16.6
The multiplication of given two floating-point numbers: 257.3

 

In the above program, two float values 15.5,16.6 (get input from the user) are stored in n1 and n2. Then n1 and n2 are multiplied using the multiplication(*) operator.

Then the result is stored in another variable mul.

Finally, the result is displayed on the screen using display statements in C#

 

Similar post

Java program to multiply two numbers

C program to multiply two numbers

C++ program to multiply two numbers

Python program to multiply two numbers

 

Java program to multiply two floating-point numbers

C program to multiply two floating-point numbers

C++ program to multiply two floating-point numbers

Python program to multiply two floating-point numbers

 

Java program to multiply two numbers using methods

C program to multiply two numbers using function

C++ program to multiply two numbers using function

Python program to multiply two numbers function

Multiplication of two numbers in C#
Program to multiply two numbers using function in C#
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago