Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C# code to multiply two floating-point numbers using function

Program to multiply given two floating point numbers in C#

Posted on May 30, 2022May 31, 2022

Table of Contents

  • Program to multiply given two floating point numbers in C#
    • Code to multiply two floating-point numbers in C#
      • Multiply two floating-point numbers in C#
      • Multiply two floating-point numbers in C# – Entered by user
      • Multiply two floating-point numbers in C# – using function

Program to multiply given two floating point numbers in C#

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

Code to multiply two floating-point numbers in C#

Multiply two floating-point numbers in C#

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

 

Multiply two floating-point numbers in C# – Entered by user

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

 

Multiply two floating-point numbers in C# – using function

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

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes