Calculations

C# program: multiply two floating-point numbers using function

C# program: multiply two floating-point numbers using function

In this tutorial, we will discuss the concept of C# program: multiply two floating-point numbers using function

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

 

Multiplication of two numbers in C#

multiply two floating point numbers

Multiplication of two floating-point numbers using variable

In this program, the user declare and initialize two floating-point variables num1 and num2. Then two numbers are multiplied using multiplication(*) operator and assigned the result to third (tot_Mul) variable

Program 1

//Write a program calculate multipkication of two float numbers using function 
using System; 
public class MulFloat_Two_Num_Fun { 
    public static float mul_Num(float num1, float num2) { //function definition 
    float tot_Mul; 
    tot_Mul=num1*num2; //calculate product of two numbers 
    return tot_Mul; //return value 
    }
    public static void Main() { 
        float num1=6.5f; //declare and initialize float variable
        float num2=5.6f; 
        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 6.5 and 5.6 is: 36.4:

 

Multiplication of two floating-point numbers – Entered by user

In this program, the user declare and initialize two floating-point variables n1 and n2. Then two numbers are multiplied using multiplication(*) operator and assigned the result to third (product) variable

Program 2

// Write a program calculate product of two numbers using function 
using System; 
public class Product_Two_Num_Fun { //class declaration
    public static float product_Num(float num1, float num2) {
        //define user defined-function with parameter
        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 from user
            Console.Write("Enter number for n2: "); //Ask input from user 
            float n2=Convert.ToSingle(Console.ReadLine()); //Reading the input from user
            Console.WriteLine("The product of {0} and {1} is: {2}: ",n1,n2,product_Num(n1,n2)); } } //display result on the screen

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

Enter number for n1: 7.7
Enter number for n2: 9.9
The product of 7.7 and 9.9 is: 76.23:

 

In the above program, two float values 7.7,9.9 (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 product.

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

 

Program to multiply two numbers using function in C#
C# program for division of two numbers
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