Table of Contents
In this article, we will discuss the concept of Program to multiply given two floating point numbers in C#
In this post, we are going to learn how to write a program to multiply two floating -point numbers in C# language
In this code, we are going to learn how to write a program to multiply two floating-point numbers using initialized variables in C# programming language
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) { //main method float num1=15.34f; //declare and initialize variable for num1 float num2=20.12f; //declare and initialize variable for num2 float mul=num1*num2; //Calculate multiplication of two numbers Console.WriteLine ("The multiplication of two numbers: "+mul); } } //display output on the screen
When the above code is executed, it produces the following result
The multiplication of two numbers: 308.6408
In this example, the user is asked to enter two floating-point numbers. Then the multiplication of these two floating-point numbers is calculated and displayed on the screen in C#
Program 2
// 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 n1, n2, mul; //declare variables Console.WriteLine("Find multiplication of two floating point numbers: "); Console.Write("Input number to n1: "); //Ask input from the user for n1 n1=Convert.ToSingle(Console.ReadLine()); //Reading the value for n1 Console.Write("Input number to n2: "); //Ask input from the user for n2 n2=Convert.ToSingle(Console.ReadLine()); //Reading the value for n2 mul=n1*n2; //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
Find multiplication of two floating point numbers: Input number to n1: 5.12 Input number to n2: 6.23 The multiplication of given two floating-point numbers: 31.8976
In the above code, the user asked to enter two floating-point numbers and the given floating-point numbers are stored in variables n1 and n2 respectively.
Then these two numbers are multiplied using the multiplication(*) operator and the result is stored in the mul variable.
Finally the display statement is used to print the multiplication of numbers
In this example, the user is asked to enter two floating-point numbers. Then the multiplication of these two floating-point numbers is calculated and displayed on the screen using user defined function in C#
Program 3
// Write a program calculate product of two numbers using function using System; public class mul_Two_Num_Fun { //class declaration public static float pro_Num(float num1, float num2) { float product; //declare float variable product=num1*num2; //calculate multiplication of the given numbers return product;//return value to main method } public static void Main() { //main method Console.Write("Enter number for n1: "); //Ask input from user float n1=Convert.ToSingle(Console.ReadLine()); //Reading the input Console.Write("Enter number for n2: "); //Ask input from user float n2=Convert.ToSingle(Console.ReadLine()); //Reading the input Console.WriteLine("The multiplication of {0} and {1} is: {2}: ",n1,n2,pro_Num(n1,n2)); } } //display result on the screen
When the above code is executed, it produces the following result
Enter number for n1: 6.4 Enter number for n2: 8.5 The multiplication of 6.4 and 8.5 is: 54.4:
Similar post
Java program to multiplication of two numbers
C++ program to multiplication of two numbers
C program to multiplication of two numbers
Python program to multiplication of two numbers
Java program to multiplication of 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 print multiplication table
C program to print multiplication table
C++ program to print multiplication table
Python program to print multiplication table
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.