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
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
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# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…