Arithmetic Caculation

C# – floating point division using functions

C# – floating point division using functions

In this article, we will discuss the concept of C# – floating point division using functions

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

Code to division of two numbers in C#

Division of two floating-point  numbers using function

In this code, we are going to learn how to write a program to division of two floating-point numbers using function in C# programming language

Program 1

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

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

The division of 3.3 and 2.2 is: 1.5:

 

Division of two floating-point numbers using  function- Entered by user

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

Program 2

// Write a program calculate divisionion of two numbers using function 
using System; 
public class Div_Two_Num_Fun { 
    public static float div_Num(float num1, float num2) { 
        float div; //declare float variable 
        div=num1/num2; //calculate division of the given numbers 
        return div;//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 division of {0} and {1} is: {2}: ",n1,n2,div_Num(n1,n2)); } } //display result on the screen

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

Enter number for n1: 21.32
Enter number for n2: 5.2
The division of 21.32 and 5.2 is: 4.1:

 

In this code, the user asked to enter two  floating-point numbers and the given numbers are stored in variables n1 and  n2 respectively.

Then those two numbers are divided using the division(/) operator and the result is stored in the div variable.

Finally the display statement is used to print the division of numbers

 

Suggested post

Java program  to divide   two number

C program  to divide   two number

C++ program  to divide   two number

Python program  to divide   two number

 

java program to find quotient and remainder

C program to find quotient and remainder 

C++ program to find quotient and remainder

Python program to find quotient and remainder 

 

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

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.