Arithmetic Caculation

C# code to multiply two floating-point numbers using function

C# code to multiply two floating-point numbers using function

In this article, we will discuss the concept of C# code to multiply two floating-point numbers using function

In this post, we are going to learn how to write a program to multiply two floating-point numbers using function  in C# language

Code to multiplication of two floating-point numbers

Multiplication of two numbers in C# using function

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

//Write a program calculate multiplication of two float numbers using function 
using System; 
public class MulFloat_Two_Num_Fun { //class declaration
    public static float mul_Num(float num1, float num2) { //function definition 
    float product; //declare variable to assign result
    product=num1*num2; //calculate product of two numbers 
    return product; //return value to main
    }
    public static void Main() { //main method
        float num1=3.5f; //declare and initialize float variable
        float num2=5.4f; 
        Console.WriteLine("The product of {0} and {1} is: {2}: ",num1,num2,mul_Num(num1,num2)); //display result on the screen 
        } 
}

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

The product of 3.5 and 5.4 is: 18.9:

 

Multiplication of two numbers in C# using function – Entered by user

In this example, the user is asked to enter two floating-point numbers. Then the multiplication of the these two numbers is calculated and displayed on the screen in C#

Program 2

// Write a program calculate multiplication of two numbers using function 
using System; public class mul_Two_Num_Fun { 
    public static float mul_Num(float num1, float num2) { 
        float mul; //declare float variable 
        mul=num1*num2; //calculate multiplication of the given numbers
        return mul;//return value to main method 
        } public static void Main() { 
            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,mul_Num(n1,n2)); } } //display result on the screen

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

Enter number for n1: 10.2
Enter number for n2: 12.4
The multiplication of 10.2 and 12.4 is: 126.48:

 

In this code, the user asked to enter two floating-point numbers and the given integers 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

 

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 print multiplication table

C program to print multiplication table

C++ program to print  multiplication table

Python program to print multiplication table

 

 

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.