Arithmetic Caculation

Program to divide two floating point numbers in C#

Program to divide two floating point numbers in C#

In this article, we will discuss the concept of Program to divide two floating point numbers in C#

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 floating-point numbers in C#

Division of two floating-point  numbers in C#

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

Program 1

// Calculate division of two floating-point numbers in C# program
using System; 
public class Float_Division{ 
    public static void Main(string[] args) { 
    float firstNum=65.34f;//declare and initialize variables for firstNum
    float lastNum=9.9f; //declare and initialize variables for lastNum
    float divResult=firstNum/lastNum; //Calculate division of two numbers 
        //assign the result to div variable
        Console.WriteLine ("The division of given two floating point numbers: "+divResult); } } //display result on the screen

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

The division of given two floating point numbers: 6.6

 

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

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

Program 2

// Calculate division of two floating-point numbers in C# program
using System; 
public class Div_Of_Two_Num { 
    public static void Main(string[] args) { 
        float num_First, num_Last, division; //declare floating point variables
    Console.WriteLine("Find division of two floating point numbers");
    Console.Write("Input first number: "); 
    //Ask input from the user
    num_First=Convert.ToSingle(Console.ReadLine()); 
    //Reading the input
    Console.Write("Input last number "); 
     //Ask input from the user
    num_Last=Convert.ToSingle(Console.ReadLine()); 
        //Reading the input
    division=num_First/num_Last;//Calculate division of given two numbers
Console.WriteLine ("The division of given two floating point numbers: "+division); 
Console.ReadKey(); } }

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

Find division of two floating point numbers
Input first number: 76.63
Input last number 9.7
The division of given two floating point numbers: 7.9

 

In this code, the user asked to enter two floating-point values and the given values are stored in variables num_First and   num_Last respectively.

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

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

 

Division of two floating-point numbers in C# – using function

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

// Write a program calculate divisionion of two numbers using function 
using System; 
public class Division_Two_Num_Fun { 
    public static float div_Num(float num1, float num2) { 
        float divResult; //declare float variable 
        divResult=num1/num2; //calculate division of the given numbers 
        return divResult;//return value to main method 
        } 
        public static void Main() { Console.Write("Enter number for fNum: "); //Ask input from user 
        float fNum=Convert.ToSingle(Console.ReadLine()); //Reading the input 
        Console.Write("Enter number for lNum: "); //Ask input from user 
        float lNum=Convert.ToSingle(Console.ReadLine()); //Reading the input 
        Console.WriteLine("The division of {0} and {1} is: {2}: ",fNum,lNum,div_Num(fNum,lNum)); } } //display result on the screen

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

Enter number for fNum: 2.42
Enter number for lNum: 1.1
The division of 2.42 and 1.1 is: 2.2:

 

 

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 

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

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,…

1 year 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…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

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

1 year 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…

1 year ago

This website uses cookies.